sqlalchemy postgresql enum does not create type on db migrate
I decided on this problem using that.
I changed the code of migration, and migration looks like this:
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
banner_status = postgresql.ENUM('active', 'inactive', 'archive', name='banner_status')
banner_status.create(op.get_bind())
op.add_column('banner', sa.Column('status', sa.Enum('active', 'inactive', 'archive', name='banner_status'), nullable=True))
def downgrade():
op.drop_column('banner', 'status')
banner_status = postgresql.ENUM('active', 'inactive', 'archive', name='banner_status')
banner_status.drop(op.get_bind())
And now python manage.py db upgrade\downgrade
is successfully executed.
I think this way is more simple:
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
# others_column = ...
banner_status = postgresql.ENUM('active', 'inactive', 'archive', name='banner_status', create_type=False), nullable=False)
Also added the postgresql.ENUM
to your downgrade()
function if that needed.