[2.2.x] Fixed #30597 -- Clarified how to unapply migrations.

Backport of 45554fd5c5 from master
This commit is contained in:
David Vaz 2019-09-26 10:39:36 -07:00 committed by Mariusz Felisiak
parent 1ac2f25ec0
commit 4116b369b1
2 changed files with 26 additions and 2 deletions

View File

@ -801,8 +801,8 @@ The behavior of this command changes depending on the arguments provided:
* ``<app_label> <migrationname>``: Brings the database schema to a state where * ``<app_label> <migrationname>``: Brings the database schema to a state where
the named migration is applied, but no later migrations in the same app are the named migration is applied, but no later migrations in the same app are
applied. This may involve unapplying migrations if you have previously applied. This may involve unapplying migrations if you have previously
migrated past the named migration. Use the name ``zero`` to unapply all migrated past the named migration. Use the name ``zero`` to migrate all the
migrations for an app. way back i.e. to revert all applied migrations for an app.
.. warning:: .. warning::

View File

@ -349,6 +349,30 @@ Note that this only works given two things:
that your database doesn't match your models, you'll just get errors when that your database doesn't match your models, you'll just get errors when
migrations try to modify those tables. migrations try to modify those tables.
Reverting migrations
====================
Any migration can be reverted with :djadmin:`migrate` by using the number of
previous migrations::
$ python manage.py migrate books 0002
Operations to perform:
Target specific migration: 0002_auto, from books
Running migrations:
Rendering model states... DONE
Unapplying books.0003_auto... OK
If you want to revert all migrations applied for an app, use the name
``zero``::
$ python manage.py migrate books zero
Operations to perform:
Unapply all migrations: books
Running migrations:
Rendering model states... DONE
Unapplying books.0002_auto... OK
Unapplying books.0001_initial... OK
.. _historical-models: .. _historical-models:
Historical models Historical models