3

Why the following code dont work?

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')
op.alter_column('testcaseresult', u'status', type_=new_type,
                existing_type=old_type)
tapioco123
  • 3,235
  • 10
  • 36
  • 42
  • 2
    What does "not work" mean? Exception? Error message? Or does something happen that is wrong in any way? Or does nothing happen? Which SQL queries are being run? What is the backend you use (e.g. MySQL? Sqlite?)? You provide very little detail for us to help you. – javex Mar 24 '14 at 18:02
  • No exception, no error message, migrate_version in database is updated, but the postgresql type isn't. Not the OP, but just found myself in the same situation. – jneves Apr 16 '18 at 14:34
  • Ended up doing an ALTER TYPE on postgresql, but would like to know if I missed something. – jneves Apr 16 '18 at 14:45

1 Answers1

7

Alembic has problems with Enum field

Try use this example

from sqlalchemy.dialects import postgresql    

def upgrade():
    priority = postgresql.ENUM('H', 'M', 'L', name='priority')
    priority.create(op.get_bind())
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('tasks', sa.Column('priority', sa.Enum('H', 'M', 'L', name='priority'), nullable=True))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('tasks', 'priority')
    priority = postgresql.ENUM('H', 'M', 'L', name='priority')
    priority.drop(op.get_bind())
    # ### end Alembic commands ###
Headmaster
  • 2,008
  • 4
  • 24
  • 51
  • 1
    The code you provide is to add a new column as Enum type, not alter from old Enum to new Enum as OP wanted. – RedNam Oct 07 '20 at 10:02