From 8f4877c89d0f28e289399fbb46357623a49e7eb0 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Fri, 9 Jan 2015 00:10:10 +0700 Subject: Fixed #22583 -- Allowed RunPython and RunSQL to provide hints to the db router. Thanks Markus Holtermann and Tim Graham for the review. --- docs/ref/migration-operations.txt | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'docs/ref') diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt index dcac7f26a6..8e13974cfe 100644 --- a/docs/ref/migration-operations.txt +++ b/docs/ref/migration-operations.txt @@ -206,7 +206,7 @@ Special Operations RunSQL ------ -.. class:: RunSQL(sql, reverse_sql=None, state_operations=None) +.. class:: RunSQL(sql, reverse_sql=None, state_operations=None, hints=None) Allows running of arbitrary SQL on the database - useful for more advanced features of database backends that Django doesn't support directly, like @@ -235,6 +235,11 @@ 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). +The optional ``hints`` argument will be passed as ``**hints`` to the +:meth:`allow_migrate` method of database routers to assist them in making +routing decisions. See :ref:`topics-db-multi-db-hints` for more details on +database hints. + .. versionchanged:: 1.7.1 If you want to include literal percent signs in a query without parameters @@ -245,6 +250,8 @@ operation that adds that field and so will try to run it again). The ability to pass parameters to the ``sql`` and ``reverse_sql`` queries was added. + The ``hints`` argument was added. + .. attribute:: RunSQL.noop .. versionadded:: 1.8 @@ -258,7 +265,7 @@ operation that adds that field and so will try to run it again). RunPython --------- -.. class:: RunPython(code, reverse_code=None, atomic=True) +.. class:: RunPython(code, reverse_code=None, atomic=True, hints=None) Runs custom Python code in a historical context. ``code`` (and ``reverse_code`` if supplied) should be callable objects that accept two arguments; the first is @@ -267,6 +274,15 @@ match the operation's place in the project history, and the second is an instance of :class:`SchemaEditor `. +The optional ``hints`` argument will be passed as ``**hints`` to the +:meth:`allow_migrate` method of database routers to assist them in making a +routing decision. See :ref:`topics-db-multi-db-hints` for more details on +database hints. + +.. versionadded:: 1.8 + + The ``hints`` argument was added. + You are advised to write the code as a separate function above the ``Migration`` class in the migration file, and just pass it to ``RunPython``. Here's an example of using ``RunPython`` to create some initial objects on a ``Country`` -- cgit v1.3