在我的 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 呢?