summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2020-03-25 13:37:54 +0000
committerCarlton Gibson <carlton.gibson@noumenal.es>2020-03-25 14:39:17 +0100
commitc740a994fa2744a3f1d69d5717bda8d563e7946b (patch)
tree76983907511e845779234c74b44c49acf17caece /docs/ref
parent76db34e52a7852dc292a1792c8a0499ac65faced (diff)
[3.0.x] Improved docs on migration reversibility.
- Clarify reversibility for RunSQL and RunPython operations. - Add example for migrate with irreversible migration. Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es> Backport of b15b3706fec8ef59577ac47118ee0c62132a03a6 from master
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/migration-operations.txt15
1 files changed, 10 insertions, 5 deletions
diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt
index 412d5196a6..5c4f09e08f 100644
--- a/docs/ref/migration-operations.txt
+++ b/docs/ref/migration-operations.txt
@@ -267,14 +267,18 @@ queries and parameters in the same way as :ref:`cursor.execute()
If you want to include literal percent signs in the query, you have to double
them if you are passing parameters.
-The ``reverse_sql`` queries are executed when the migration is unapplied, so
-you can reverse the changes done in the forwards queries::
+The ``reverse_sql`` queries are executed when the migration is unapplied. They
+should undo what is done by the ``sql`` queries. For example, to undo the above
+insertion with a deletion::
migrations.RunSQL(
- [("INSERT INTO musician (name) VALUES (%s);", ['Reinhardt'])],
- [("DELETE FROM musician where name=%s;", ['Reinhardt'])],
+ sql=[("INSERT INTO musician (name) VALUES (%s);", ['Reinhardt'])],
+ reverse_sql=[("DELETE FROM musician where name=%s;", ['Reinhardt'])],
)
+If ``reverse_sql`` is ``None`` (the default), the ``RunSQL`` operation is
+irreversible.
+
The ``state_operations`` argument is so you can supply operations that are
equivalent to the SQL in terms of project state; for example, if you are
manually creating a column, you should pass in a list containing an ``AddField``
@@ -321,7 +325,8 @@ instance of :class:`SchemaEditor
The ``reverse_code`` argument is called when unapplying migrations. This
callable should undo what is done in the ``code`` callable so that the
-migration is reversible.
+migration is reversible. If ``reverse_code`` is ``None`` (the default), the
+``RunPython`` operation is irreversible.
The optional ``hints`` argument will be passed as ``**hints`` to the
:meth:`allow_migrate` method of database routers to assist them in making a