小编Анд*_*кий的帖子

将 alembic 与 sqlalchemy_utils 一起使用时出现问题

在我的 sqlalchemy 模型中,我使用 sqlalchemy_utils 的选择类型:

id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.Integer, nullable=True)
level = db.Column(mytypes.types.ChoiceType(LEVEL))
Run Code Online (Sandbox Code Playgroud)

我做了这里描述的所有事情http://alembic.readthedocs.org/en/latest/autogenerate.html#autogen-module-prefix。在我的模型中,我从我的模块 mytypes.types 中导入了choicetype:

from sqlalchemy_utils.types.choice import ChoiceType
Run Code Online (Sandbox Code Playgroud)

, 在 alembic/env.py 我添加了上下文

context.configure(
    connection=connection,
    target_metadata=target_metadata,
    user_module_prefix="mytypes.types."
    # ...
)
Run Code Online (Sandbox Code Playgroud)

, 在 script.py.mako 中

import mytypes.types
Run Code Online (Sandbox Code Playgroud)

.问题是当我修改我的模型时,我得到了
这样的东西

from alembic import op
import sqlalchemy as sa
import mytypes.types

def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('logging', sa.Column('level', mytypes.types.ChoiceType(length=255), nullable=True))
### end Alembic commands ###
Run Code Online (Sandbox Code Playgroud)

为什么 alembic 没有将“LEVEL”参数传递给choicetype,为什么它传递了 length=255 呢?

python sqlalchemy alembic

6
推荐指数
3
解决办法
2212
查看次数

标签 统计

alembic ×1

python ×1

sqlalchemy ×1