0

I'm trying to automate upgrade of database for project written in Flask. I use alembic for Flask.

The problem is when I use several enums it always run the error on the second enum, I don't understand why and how to fix it.

File enums.py:

from enum import Enum

class A(Enum):
    i = 'i'
    a = 'a'

class B(Enum):
    a = 'a'
    b = 'b'

Model that uses them:

from enums import A, B

class Test(db.Model):
    status_a = db.Column(db.Enum(A)) 
    status_b = db.Column(db.Enum(B))

Now I'm doing the upgrade:

from libs import alembic
alembic.revision()
alembic.upgrade()

It always catches the error on the second enum:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) type "b" does not exist

What to do? I found some solutions but I don't how to use them, and don't understand completely what's going.

Update: migration code:

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('Account', sa.Column('activity_status', sa.Enum('inactive1', 'active1', name='abd'), nullable=True))
op.drop_column('Account', 'valid_status')
# ### end Alembic commands ###

Thanks.

mimic
  • 4,897
  • 7
  • 54
  • 93

0 Answers0