1

I recently executed flask db migrate and got an exception in between (details). The migration was only partially done.

What I did

The migration looked like this:

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    ...
    op.add_column('users', sa.Column('registered_on', sa.DateTime(), nullable=False))
    ...

Everything before the "registered_on" was done. Everything below was not. When I executed flask db upgrade again, it complained that the columns before already existed.

Next, I tried flask db downgrade and then flask db upgrade. That worked, but now all the data is lost (not too bad, it was a development environment).

What should I have done to not delete all data from the database, after the migration ran only partially?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958

1 Answers1

0

After you fix the error in the migration script, you can comment out the operations in the upgrade() function that were already applied before the error occurred. Then run the upgrade again so that the remaining operations are carried out. Don't forget to uncomment after the migration script is fully applied!

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