Rerun a Django data migration

前端 未结 2 538
南笙
南笙 2020-12-08 04:03

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.

2条回答
  •  既然无缘
    2020-12-08 04:32

    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.

提交回复
热议问题