在添加/删除列时,我可以使用alembic --autogenerate
。
但是,当我想要将"url“列从200个字符修改为2000个字符时,它没有检测到更改。
如何创建Alembic (使用SQLAlchemy),检测各种列的模型“大小”的变化并自动生成脚本,以及为PostgreSQL创建"alter_column“命令?
编辑:
为什么alembic不自动添加:
op.alter_column('mytable', 'url', type_=sa.String(2000), existing_type=sa.String(length=200), nullable=True)
发布于 2013-06-19 03:03:41
看起来我在reddit的/r/flask上找到了答案。
http://www.reddit.com/r/flask/comments/1glejl/alembic_autogenerate_column_changes/cale9o0
只需在env.py的"run_migrations_online“函数内的context.configure()参数中添加"compare_type=True”即可。
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True
)
发布于 2019-08-06 22:14:53
我也遇到过这个问题,在alembic 1.0.8
上,migrations/env.py
文件上的context.configure
in def run_migrations_online()
函数将如下所示:
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args,
)
只需删除或注释process_revision_directives=process_revision_directives
,然后在上面添加compare_type=True
即可。
如下所示:
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
# process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args,
compare_type=True
)
https://stackoverflow.com/questions/17174636
复制相似问题