0

I currently have an issue with some south migrations in my django application. After doing a code merge I have come across a couple migrations with the same index. I have successfully reversed the migrations back to right before the first duplicate migration number.

  (*) 0209_auto__add_field_product_subtitle
  ( ) 0210_auto__add_field_invoice_shipping_cost
  ( ) 0210_auto__add_reminderemailmessage__add_unique_reminderemailmessage_produc
  ( ) 0211_auto__add_cmecredits
  ( ) 0211_auto__chg_field_reminderemailmessage_product_package
  ( ) 0212_auto__add_field_test_credit_limit_override
  ( ) 0212_auto__chg_field_reminderemailmessage_product_package

I am just wondering what the best approach to fixing this issue because when trying to deploy this to a development server I am getting the following error.

 ! Migration decker:0211_auto__add_cmecredits should not have been applied before decker:0210_auto__add_reminderemailmessage__add_unique_reminderemailmessage_produc but was
dnaluz
  • 135
  • 1
  • 10
  • I would first look to see if there are any data migrations. If not, why dont you delete them all regenerate a single migration. You could do a `manage.py dumpdata` and then reload it afterwards in the database. Another approach is to migrate until the first 210. Then fiddle the snapshot dictionary to match what the state looks like. Increment the subsequent migrations and it 'should' just work. – zsoobhan Aug 11 '15 at 15:17

1 Answers1

0

It's a tricky situation, but fortunately all of your migrations are auto generated. It depends on what do you want to do with your migrations. If you only care about the end result, just manually delete all the migrations after 0209 then run ./manage.py schemamigration <app-name>, it will consolidate all changes into one migration file but apparently you lose track of the migration history. There's no good way if you want to keep the content of each migration, you can only try to follow the steps for each migration and change your model accordingly, which is time consuming and error prone.

I would suggest having a process at the beginning of your deployment to check for duplicate migration files. It could be dangerous if migrations failed.

Shang Wang
  • 24,909
  • 20
  • 73
  • 94