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.

6
  • can you show your migration? Commented Oct 24, 2018 at 13:11
  • @DanilaGanchar I updated my question, thanks. Commented Oct 24, 2018 at 16:30
  • @minic I don't see migration for Test model. As I see you have problem with Test model but not with Account. Where is Test model migration? By the way you don't have primary_key. Commented Oct 24, 2018 at 20:49
  • @DanilaGanchar It's the same. I just changed model's name but code is absolutely identical. Commented Oct 24, 2018 at 20:57
  • Did you generate a new migration after changes? Commented Oct 25, 2018 at 6:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.