Skip to content

Commit

Permalink
[3.0.x] Refs #31320 -- Warned against using BEGIN/COMMIT in RunSQL.
Browse files Browse the repository at this point in the history
Backport of e9b014f from master
  • Loading branch information
adamchainz authored and felixxm committed Apr 1, 2020
1 parent 73001dd commit c943759
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions docs/ref/migration-operations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand All @@ -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;",
Expand Down

0 comments on commit c943759

Please sign in to comment.