Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13316 -- Added clarifying note about cross-database relations.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13178 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9320c866ffbfba247641f42db9954c50ad0a5c6e 1 parent ced4dd2
Russell Keith-Magee authored

Showing 1 changed file with 34 additions and 7 deletions. Show diff stats Hide diff stats

  1. 41  docs/topics/db/multi-db.txt
41  docs/topics/db/multi-db.txt
@@ -193,13 +193,11 @@ An example
193 193
     intentionally ignores some complex issues in order to
194 194
     demonstrate how routers are used.
195 195
 
196  
-    This example won't work on Postgres, Oracle, or MySQL with InnoDB
197  
-    tables if any of the models in ``myapp`` contain foreign keys to
198  
-    models outside of the ``other`` database. ForeignKeys to a remote
199  
-    database introduce referential integrity problems that Django can't
200  
-    currently handle. However, if you're using SQLite or MySQL with MyISAM
201  
-    tables, there is no referential integrity checking, so you will be
202  
-    able to define cross-database foreign keys.
  196
+    This example won't work if any of the models in ``myapp`` contain
  197
+    relationships to models outside of the ``other`` database.
  198
+    :ref:`Cross-database relationships <no_cross_database_relations>`
  199
+    introduce referential integrity problems that Django can't
  200
+    currently handle.
203 201
 
204 202
     The master/slave configuration described is also flawed -- it
205 203
     doesn't provide any solution for handling replication lag (i.e.,
@@ -547,3 +545,32 @@ alias::
547 545
 
548 546
     from django.db import connections
549 547
     cursor = connections['my_db_alias'].cursor()
  548
+
  549
+Limitations of multiple databases
  550
+=================================
  551
+
  552
+.. _no_cross_database_relations:
  553
+
  554
+Cross-database relations
  555
+------------------------
  556
+
  557
+Django doesn't currently provide any support for foreign key or
  558
+many-to-many relationships spanning multiple databases. If you
  559
+have used a router to partition models to different databases,
  560
+any foreign key and many-to-many relationships defined by those
  561
+models must be internal to a single database.
  562
+
  563
+This is because of referential integrity. In order to maintain a
  564
+relationship between two objects, Django needs to know that the
  565
+primary key of the related object is valid. If the primary key is
  566
+stored on a separate database, it's not possible to easily evaluate
  567
+the validity of a primary key.
  568
+
  569
+If you're using Postgres, Oracle, or MySQL with InnoDB, this is
  570
+enforced at the database integrity level -- database level key
  571
+constraints prevent the creation of relations that can't be validated.
  572
+
  573
+However, if you're using SQLite or MySQL with MyISAM tables, there is
  574
+no enforced referential integrity; as a result, you may be able to
  575
+'fake' cross database foreign keys. However, this configuration is not
  576
+officially supported by Django.

0 notes on commit 9320c86

Please sign in to comment.
Something went wrong with that request. Please try again.