5

我正在尝试使用烧瓶、sqlalchemy 和 flask_migrate...

但是每次运行 manage.py migrate 时,alembic 总是将我的模型检测为新表。

我认为我将 table_args放在我的模型中以将表存储在不同的 postgres 模式中:

class Entry(db.Model):
    __table_args__ = {'schema': app.config['BASE_SCH']}
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    slug = db.Column(db.String(100), unique=True)
    body = db.Column(db.Text)
    status = db.Column(db.SmallInteger, default=STATUS_PUBLIC)
    created_timestamp = db.Column(db.DateTime, default=datetime.datetime.now)
    modified_timestamp = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)

如果我删除模型的table_args行,烧瓶迁移工作正常。将我的表存储在 puclic postgres 模式中。

那么,如何在烧瓶中使用不同的 postgres 表模式?

谢谢!

4

1 回答 1

8

Finally figured this out: there is an include_schemas option in configure that you have to set to True to force Alembic to scan all schemas before generating the migration.

(Slightly) more details: http://alembic.zzzcomputing.com/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.include_schemas

It's not completely clear to me why Alembic/Flask-Migrate was generating the migrations for tables in non default schemas without this option set in the first place... or rather, the fact that it would create migrations for non default schemas but not discover these tables in the DB is a surprising behavior.

于 2017-11-30T04:43:20.013 回答