Preserve existing tables in database when running Flask-Migrate

拥有回忆 提交于 2019-12-03 15:35:24

If you have existing tables in your database, and they don't have a corresponding model in your code, Alembic (Flask-Migrate) only knows that there is a difference between your database and your code. It can't know (by default) that you meant to leave those tables untouched.

Pass an include_object function to the environment to effect what database objects Alembic will generate commands for. The following example skips the listed table names, but allows everything else.

def include_object(object, name, type_, reflected, compare_to):
    if type_ == 'table' and name in ('table', 'names', 'to', 'skip'):
        return False

    return True

# in env.py
context.configure(
    # ...
    include_object=include_object
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!