可以Alembic自动生成列更改? [英] Can Alembic Autogenerate column alterations?

查看:218
本文介绍了可以Alembic自动生成列更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在添加/删除列时,我可以使用
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上找到了答案。



http://www.reddit.com/r/flask/comments/1glejl/alembic_autogenerate_col只要在env.py的run_migrations_online函数中添加compare_type = True到context.configure()参数即可。


$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆