Suppose I have following migrations in Django.
X
/ \
A B [A and B can represent any number of linear migrations.]
\ /
Y (merge migration).
Doing python manage.py migrate app X
will unapply all of A, B and Y.
How can I unapply only B and Y?. And keep A as it is, i.e applied.
CodePudding user response:
X(*) [* represent migration has been applied.]
/ \
A(*) B(*) [A and B can represent any number of linear migrations.]
\ /
Y(*) (merge migration)
Steps to unapply only one path i.e B and Y
Unapply only Y. By doing
python manage.py migrate app B (or A; both works)
.X(*) / \ A(*) B(*) \ / Y()
Remove the migration files A and Y for time being from the project location.
X(*) \ B(*)
Now unapply B, by doing
python manage.py migrate app X
.X(*) \ B()
Bring the migration files A and Y to the original location. You can now safely delete the unapplied migrations B and Y, if you wish to.
X(*) / \ A(*) B() \ / Y()
The gist is, django can only rollback migrations if the files are present in the location. If you do not want to rollback a migration path (i.e A here), remove it from the project location while performing rollback.