Existing PostgreSQL ENUMs in Alembic
If you drop/modify a table or try to add a column using an existing ENUM, alembic will complain:
sqlalchemy.exc.ProgrammingError: (ProgrammingError) type "zone" already exists
"CREATE TYPE zone AS ENUM ('uk_mainland', 'uk_channel_islands' )"
The quick fix is to edit the migration file and add
create_type=False
to the end of the constructor:
sa.Column('zone', postgresql.ENUM('uk_mainland', 'uk_channel_islands', name='zone', create_type=False), nullable=False)
That disables the creation attempt and saves you having to drop the types manually.
Written by Iain Campbell
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#