Alembic试图删除我之前存在的Postgres表

时间:2017-10-27 22:04:22

标签: python postgresql sqlalchemy alembic

您好我正在尝试使用SQLAlchemy扩展包含一个表的预先存在的Postgres数据库。但是当我尝试使用迁移时,我从alembic迁移中得到了这个:

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

这是我的修订文件:

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')
    )

我的Postgres表:

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

我的__ 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)

我的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)

为什么会发生这种情况的任何想法?

0 个答案:

没有答案