有没有办法强制 alembic 跟踪导入的模型?

Is there a way to force alembic to track imported models?

我正在尝试编写一个使用 cd34/apex 项目进行身份验证的金字塔应用程序。其中,auth 的模型已经是 apex 项目的一部分,在运行时导入。 Alembic 似乎忽略了那些模型,即使我在 env.py 中导入它们也是如此。

我尝试在自己的模型中从顶点延伸 类:

from apex.models import (
    AuthUser,
    AuthUserLog,
    AuthGroup,
    AuthID
)


class EAuthUser(AuthUser):
    pass


class EAuthUserLog(AuthUserLog):
    pass


class EAuthGroup(AuthGroup):
    pass


class EAuthID(AuthID):
    pass

但是当我使用 --autogenerate:

时,alembic 仍然会掉落 tables
op.drop_table('auth_user_log')
op.drop_table('auth_users')
op.drop_table('auth_groups')
op.drop_table('auth_id')
op.drop_table('auth_auth_groups')

我可以做些什么让 alembic 忽略特定的 table 名称,或者更好的是,让它跟踪并遵循另一个项目中的模型定义?

确保您的 env.py 引用这些模型使用的元数据,以及当 env.py 运行时,它会导入确保这些模块全部被调用和导入所需的一切。