summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/db/multi-db.txt6
-rw-r--r--docs/topics/migrations.txt20
2 files changed, 12 insertions, 14 deletions
diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt
index 7d4f2465c9..76df8610e3 100644
--- a/docs/topics/db/multi-db.txt
+++ b/docs/topics/db/multi-db.txt
@@ -150,7 +150,7 @@ A database Router is a class that provides up to four methods:
used by foreign key and many to many operations to determine if a
relation should be allowed between two objects.
-.. method:: allow_migrate(db, model)
+.. method:: allow_migrate(db, model, **hints)
Determine if the ``model`` should have tables/indexes created in the
database with alias ``db``. Return True if the model should be
@@ -293,7 +293,7 @@ send queries for the ``auth`` app to ``auth_db``::
return True
return None
- def allow_migrate(self, db, model):
+ def allow_migrate(self, db, model, **hints):
"""
Make sure the auth app only appears in the 'auth_db'
database.
@@ -333,7 +333,7 @@ from::
return True
return None
- def allow_migrate(self, db, model):
+ def allow_migrate(self, db, model, **hints):
"""
All non-auth models end up in this pool.
"""
diff --git a/docs/topics/migrations.txt b/docs/topics/migrations.txt
index 48021c724e..1220b4b41f 100644
--- a/docs/topics/migrations.txt
+++ b/docs/topics/migrations.txt
@@ -545,28 +545,26 @@ attribute::
migrations.RunPython(forwards),
]
-You can also use your database router's ``allow_migrate()`` method, but keep in
-mind that the imported router needs to stay around as long as it is referenced
-inside a migration:
+.. versionadded:: 1.8
+
+You can also provide hints that will be passed to the :meth:`allow_migrate()`
+method of database routers as ``**hints``:
.. snippet::
:filename: myapp/dbrouters.py
class MyRouter(object):
- def allow_migrate(self, db, model):
- return db == 'default'
+ def allow_migrate(self, db, model, **hints):
+ if 'target_db' in hints:
+ return db == hints['target_db']
+ return True
Then, to leverage this in your migrations, do the following::
from django.db import migrations
- from myappname.dbrouters import MyRouter
-
def forwards(apps, schema_editor):
- MyModel = apps.get_model("myappname", "MyModel")
- if not MyRouter().allow_migrate(schema_editor.connection.alias, MyModel):
- return
# Your migration code goes here
class Migration(migrations.Migration):
@@ -576,7 +574,7 @@ Then, to leverage this in your migrations, do the following::
]
operations = [
- migrations.RunPython(forwards),
+ migrations.RunPython(forwards, hints={'target_db': 'default'}),
]
More advanced migrations