summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2020-04-01 09:58:41 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-01 10:59:42 +0200
commitc9437596fe54fb5cf0330ee5a96e260903a2d683 (patch)
treea7c494c95b943a89a91e396d3403f9c2099b7147 /docs
parent73001dd8ad38a1c77c074c36660a8243082db5de (diff)
[3.0.x] Refs #31320 -- Warned against using BEGIN/COMMIT in RunSQL.
Backport of e9b014fbc56b9baf91019a803ab2a45788c5c44a from master
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/migration-operations.txt14
1 files changed, 10 insertions, 4 deletions
diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt
index 5c4f09e08f..3e85f72d4e 100644
--- a/docs/ref/migration-operations.txt
+++ b/docs/ref/migration-operations.txt
@@ -256,6 +256,12 @@ features of database backends that Django doesn't support directly.
the database. On most database backends (all but PostgreSQL), Django will
split the SQL into individual statements prior to executing them.
+.. warning::
+
+ On PostgreSQL and SQLite, only use ``BEGIN`` or ``COMMIT`` in your SQL in
+ :ref:`non-atomic migrations <non-atomic-migrations>`, to avoid breaking
+ Django's transaction state.
+
You can also pass a list of strings or 2-tuples. The latter is used for passing
queries and parameters in the same way as :ref:`cursor.execute()
<executing-custom-sql>`. These three operations are equivalent::
@@ -279,12 +285,12 @@ insertion with a deletion::
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
+The ``state_operations`` argument allows you to 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``
operation here so that the autodetector still has an up-to-date state of the
-model (otherwise, when you next run ``makemigrations``, it won't see any
-operation that adds that field and so will try to run it again). For example::
+model. If you don't, when you next run ``makemigrations``, it won't see any
+operation that adds that field and so will try to run it again. For example::
migrations.RunSQL(
"ALTER TABLE musician ADD COLUMN name varchar(255) NOT NULL;",