How to use django models with foreign keys in different DBs?

Cross-database limitations

Django doesn’t currently provide any support for foreign key or many-to-many relationships spanning multiple databases. If you have used a router to partition models to different databases, any foreign key and many-to-many relationships defined by those models must be internal to a single database.

Django – limitations-of-multiple-databases

Trouble

Same trouble. Bug in ForeignKey() class.

In validate() method.

See ticket

Bug exists in v1.2, v1.3, v1.4rc1

Solution

Try this patch to solve it.

Leave a Comment