Flask-migrate: Downgrade don't drop ENUM Column Types

Created on 5 Mar 2015  路  4Comments  路  Source: miguelgrinberg/Flask-Migrate

Migration script don't contains the statements for custom type drops.

if we have a table with an ENUM field say,

class A {
...
   col = db.Column( db.Enum('a','b','c', name='custom_type'), default='a'),
...
}

Current Migration Script has been generated as follows,

def upgrade():

 op.create_table('A',
...   
 sa.Column('type', sa.Enum('a', 'b','c', name='custom_type'), nullable=True),
...

)

def downgrade():

 op.drop_table('A')

It don't drop the custom enum type generated, so If we downgrade once next time when we upgrade it breaks as

 sqlalchemy.exc.ProgrammingError: (ProgrammingError) type "custom_types" already exists

Migration script should add the 'custom type' drop statement like below,

sa.Enum(name='custom_types').drop(op.get_bind(), checkfirst=False)
invalid

Most helpful comment

If anyone comes here from Google.
This is the Issue you are looking for: https://github.com/sqlalchemy/alembic/issues/89

All 4 comments

Flask-Migrate's migrations are generated by Alembic. You need to write a bug for Alembic at https://bitbucket.org/zzzeek/alembic/issues?status=new&status=open.

@miguelgrinberg Is Flask-Migrate using the latest 0.7.5 version of Alembic ?

Flask-Migrate works with any version of Alembic from 0.6 and up.

If anyone comes here from Google.
This is the Issue you are looking for: https://github.com/sqlalchemy/alembic/issues/89

Was this page helpful?
0 / 5 - 0 ratings