Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alembic and enum type

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)
like image 293
tapioco123 Avatar asked Mar 26 '26 13:03

tapioco123


1 Answers

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 ###
like image 58
Headmaster Avatar answered Mar 29 '26 03:03

Headmaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!