0

Hello I am trying extend my pre-existing Postgres database that containing one table using SQLAlchemy. But when I am trying use migrate, I have this from alembic migration:

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.ddl.postgresql] Detected sequence named 'vocabulary_id_seq' as owned by integer column 'vocabulary(id)', assuming SERIAL and omitting
INFO  [alembic.autogenerate.compare] Detected removed table 'vocabulary'
INFO  [alembic.ddl.postgresql] Detected sequence named 'users_id_seq' as owned by integer column 'users(id)', assuming SERIAL and omitting
Generating /home/alex/prog/projects/FlaskHasherChallenge/migrations/versions/c4f
456d9500d_.py ... done

Here is my revision file:

def upgrade():
    op.drop_table('vocabulary')

def downgrade():

    op.create_table('vocabulary',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('word', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name='vocabulary_pkey')
    )

My Postgres table:

 id     | integer                | not null default nextval('vocabulary_id_seq'::regclass)
 word   | character varying(255) | 

Part of my __ init__.py:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
import os

engine = create_engine(os.environ['DATABASE_URL'])
Base = declarative_base(bind=engine)

And part of my models.py:

from . import Base, db

class Vocabulary(Base):
    __tablename__ = "vocabulary"
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    word = db.Column(db.String(255))
    hash_word = db.Column(db.String(JSON))
    author_id = db.Column(db.Integer, db.ForeignKey("users.id"))

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

Any ideas why this might be happening?

davidism
  • 121,510
  • 29
  • 395
  • 339

0 Answers0