In the documentation for the new version of Django, there is an ambiguity between what is indicated in the text and the code shown.
In the section describing the configuration of several databases, he talks about the configuration of the router, and there is a way:
allow_relation(obj1, obj2, **hints)
Return True if the relation between obj1 and obj2 should be allowed, False if this relation should be prevented, or None if the router has no opinion. This is purely a validation operation used by a foreign key, and from many to many operations, to determine whether a relationship should be allowed between two objects.
At the end of the documentation there is the following:
Django does not currently support foreign key support or many-to-many relationships spanning multiple databases. If you have used a router to separate models into different databases, any foreign key and many-to-many relationships defined by these models should be inside the same database.
This is due to referential integrity. To maintain the relationship between the two objects, Django needs to know that the primary key of the associated object is valid. If the primary key is stored in a separate database, it cannot be easily estimated the validity of the primary key.
But the example code for the router is as follows:
def allow_relation(self, obj1, obj2, **hints):
"""
Relations between objects are allowed if both objects are
in the primary/replica pool.
"""
db_list = ('primary', 'replica1', 'replica2')
if obj1._state.db in db_list and obj2._state.db in db_list:
return True
return None
Thus, even if objects are from different databases, the relationship is allowed by the software.
Does anyone know what that means?
Thanks.