【发布时间】:2019-03-04 07:45:20
【问题描述】:
我正在尝试使用 alembic 为我的数据库自动生成修订版。这样做时,我想忽略一些模型(它们具有当前版本的 MySQL 不支持的数据类型)。这是我尝试过的,它似乎工作正常,但我不确定这是最惯用的方法
在alembic/env.py内
def include_object(object, type_, name, reflected, compare_to):
if type_ == 'table' and name == 'model_to_be_ignored':
return False
return True
然后在run_migrations_online 和run_migrations_offline 中我给了include_object=include_object,这似乎工作正常。
理想情况下,我想使用skip_autogenerate=True,但不确定我是否可以定义它,以便稍后我可以简单地删除models.py 中的那一行,并在升级到更新版本的数据库时获得我想要的行为。
我有什么遗漏吗?
【问题讨论】:
标签: python sqlalchemy alembic