如何在使用PostgreSQL版本比9.1(其中添加了ALUM TYPE for enums)的情况下将元素添加到alembic迁移中的Enum字段? This这个问题解释了直接过程,但我不太确定如何最好地使用alembic来翻译它。使用Alembic更改Enum字段
这是我有:
new_type = sa.Enum('nonexistent_executable', 'output_limit_exceeded',
'signal', 'success', 'timed_out', name='status')
old_type = sa.Enum('nonexistent_executable', 'signal', 'success', 'timed_out',
name='status')
tcr = sa.sql.table('testcaseresult',
sa.Column('status', new_type, nullable=False))
def upgrade():
op.alter_column('testcaseresult', u'status', type_=new_type,
existing_type=old_type)
def downgrade():
op.execute(tcr.update().where(tcr.c.status==u'output_limit_exceeded')
.values(status='timed_out'))
op.alter_column('testcaseresult', u'status', type_=old_type,
existing_type=new_type)
以上可惜只产生ALTER TABLE testcaseresult ALTER COLUMN status TYPE status
升级后,基本上什么都不做。
适用于alembic 0.7和Postgres 9.4。 PITA必须这样做。绝对希望我不必对我的ENUM进行更多的调整! – 2015-02-18 20:01:50
@ Two-BitAlchemist - 你有没有看到http://stackoverflow.com/a/16821396/176978?在Postgres 9.4上,你应该可以更简单地做到这一点。 – bboe 2015-02-20 03:30:17
是的,但不幸的是,我正在下降,而不是加入哪个似乎没有任何支持,[甚至在9.4](http://www.postgresql.org/docs/9.4/static/sql-altertype.html )。 – 2015-02-20 12:43:34