可以在alembic.ini文件中设置这个问题,通过添加ENV.py中的include_object函数来解决这个问题。在include_object中添加适用于你的数据模型的过滤器,以便alembic不会尝试为不相关的模型创建新的迁移文件。
这里是一个示例,在include_object中添加一个名为"skip_migrations"的过滤器,只在需要时调用它:
def include_object(object, name, type_, reflected, compare_to):
if "skip_migrations" in object.info:
return False
return True
然后在需要时为数据模型添加"skip_migrations"信息:
class MyModel(db.Model):
__tablename__ = 'my_table'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(255))
__table_args__ = {'info': {'skip_migrations': True}}
这将阻止alembic为这个模型创建新的迁移文件。