0

I have a sample Table

class a(Base):
    __tablename__ = 'a'
    id = Column(Integer,primary_key=True)
    username = Column(VARCHAR(255))

Now I made some changes to my other tables and also added unique constraint to "username" column in the table shown above.

class a(Base):
    __tablename__ = 'a'
    id = Column(Integer,primary_key=True)
    username = Column(VARCHAR(255),unique=True)  # unique key added.

I run python run.py db migrate command and it detects all changes. No issue. Now I run python run.py db upgrade. This makes all schema changes in the database but fails at the unique constraint of the above mentioned table, because that table already have repeated data. Now I need to revert all the db changes to come back to my previous version ( i can't figure how to do it). Is there anyway to test if the all the upgrades run properly before commiting schema changes to database ? if not, please help me how to revert all the db changes.

Uchiha Madara
  • 984
  • 5
  • 16
  • 35

1 Answers1

0

Alembic treats the changes in a migration as an atomic change. If the last thing in your migration fails, then the whole migration is discarded, so you are always left with a consistent database.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152