summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2014-09-16 02:25:02 +0200
committerTim Graham <timograham@gmail.com>2014-10-02 11:52:40 -0400
commit85f6d893138c052f0fa24d7c2005b9c222af91b4 (patch)
tree5bafbad93e08d328520cfd1a654530908c2ca2e9 /docs/ref
parentd49993fa8f3fb10fde43983a323d53dfba815db9 (diff)
Fixed #23426 -- Allowed parameters in migrations.RunSQL
Thanks tchaumeny and Loic for reviews.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/migration-operations.txt20
1 files changed, 18 insertions, 2 deletions
diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt
index 2c5c1bb980..6998bdb574 100644
--- a/docs/ref/migration-operations.txt
+++ b/docs/ref/migration-operations.txt
@@ -188,6 +188,17 @@ the database. On most database backends (all but PostgreSQL), Django will
split the SQL into individual statements prior to executing them. This
requires installing the sqlparse_ Python library.
+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::
+
+ migrations.RunSQL("INSERT INTO musician (name) VALUES ('Reinhardt');")
+ migrations.RunSQL(["INSERT INTO musician (name) VALUES ('Reinhardt');", None])
+ migrations.RunSQL(["INSERT INTO musician (name) VALUES (%s);", ['Reinhardt']])
+
+If you want to include literal percent signs in the query, you have to double
+them if you are passing parameters.
+
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``
@@ -197,8 +208,13 @@ operation that adds that field and so will try to run it again).
.. versionchanged:: 1.7.1
- If you want to include literal percent signs in the query you don't need to
- double them anymore.
+ If you want to include literal percent signs in a query without parameters
+ you don't need to double them anymore.
+
+.. versionchanged:: 1.8
+
+ The ability to pass parameters to the ``sql`` and ``reverse_sql`` queries
+ was added.
.. _sqlparse: https://pypi.python.org/pypi/sqlparse