Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rerun a Django data migration

How would I rerun a data migration on Django 1.8+? If relevant, my migration is numbered 0011_my_data_migration.py and is the latest migration.

like image 269
davidhwang Avatar asked Aug 11 '15 23:08

davidhwang


1 Answers

Fake back to the migration before the one you want to rerun.

./manage.py migrate --fake yourapp 0010_my_previous_data_migration 

Then rerun the migration.

./manage.py migrate yourapp 0011_my_data_migration 

Then you can fake back to the most recent migration that you have run. In your case, you said that 0011 was the latest, so you can skip this stage.

./manage.py migrate --fake yourapp 0014_my_latest_data_migration 

Note that depending on the state of your database and the contents of the migrations, rerunning a migration like this might cause errors. Note the warning in the docs about the --fake option:

This is intended for advanced users to manipulate the current migration state directly if they’re manually applying changes; be warned that using --fake runs the risk of putting the migration state table into a state where manual recovery will be needed to make migrations run correctly.

like image 135
Alasdair Avatar answered Sep 27 '22 20:09

Alasdair