Let's suppose we have migrations with the following dependency graph (all applied): Initial state
Now, for some reason we want to revert database schema to the state after applying migration 0006_f
. We type:
./manage.py migrate myapp 0006_f
and now we have the following state: One branch reverted
The problem is that Django does not revert the right branch, so now we have some migrations applied from left branch and some from the right one.
One way to avoid it is to migrate back to 0002_b
and forward to 0006_f
but this can cause data loss. Also some of migrations 0006_f
, 0005_e
, 0004_d
, 0003_c
can be irreversible.
Another way is to run the following:
./manage.py migrate myapp 0006_f
./manage.py migrate myapp 0004_d1
Now, to achieve the desired state we only have to revert the migration 0004_d1
and I do not see a way to undo 0004_d1
without undoing 0006_f
, 0005_e
and 0004_d
except for opening DB shell and reverting it manually.
Is there a way to explicitly undo only one migration? Is there another way to properly undo migrations from parallel branch? Is there some reason for Django not to automatically revert migrations from parallel branch when undoing merge migration?