可以Alembic自动生成列更改? [英] Can Alembic Autogenerate column alterations?
问题描述
在添加/删除列时,我可以使用
alembic --autogenerate
>然而,当我想修改一个从200个字符到2000个字符的url列时,它不会检测到这个变化。
我怎样才能让Alembic (使用SQLAlchemy),检测更改并自动生成脚本到我的模型的各种列的大小,并创建PostgreSQL的alter_column命令??
$ b
编辑:
为什么不自动添加:
op.alter_column('mytable' ,'url',type_ = sa.String(2000),existing_type = sa.String(length = 200),nullable = True)
$ b $看起来好像我在reddit的/ r / flask上找到了答案。
$ b $ $ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' b)
I was able to use
alembic --autogenerate
for when adding / removing columns.
However, when I wanted to modify for example a "url" column from 200 characters to 2000 characters, it doesn't detect the change.
How can I make Alembic (using SQLAlchemy), detect changes and autogenerate scripts to my model's "sizes" of various columns and create "alter_column" commands for PostgreSQL ??
Edit:
Why doesn't alembic automatically add:
op.alter_column('mytable', 'url', type_=sa.String(2000), existing_type=sa.String(length=200), nullable=True)
Looks like I found the answer on reddit's /r/flask.
http://www.reddit.com/r/flask/comments/1glejl/alembic_autogenerate_column_changes/cale9o0
Just add "compare_type=True" to context.configure() parameters inside your env.py's "run_migrations_online" function.
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True
)
这篇关于可以Alembic自动生成列更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!