Alembic: alter column type with USING

∥☆過路亽.° 提交于 2019-12-03 04:22:00

Unfortunately you need to use raw SQL as alembic doesn't output a USING statement ever when changing types.

However, writing custom SQL for this is quite easy:

op.execute('ALTER TABLE views ALTER COLUMN cols TYPE bit varying USING expr')

Of course you have to replace expr with an expression that converts the old data type to the new data type.

Since version 0.8.8, alembic supports PostgreSQL's USING with the postgresql_using parameter:

op.alter_column('views', 'cols', type_=postgresql.BIT(varying=True), postgresql_using='expr')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!