You're correct, Django does not currently support foreign key relationships spanning multiple databases. From Cross-database relations [Edit 2020: Django version bump]:
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.
This is because of referential integrity. In order to maintain a relationship between two objects, Django needs to know that the primary key of the related object is valid. If the primary key is stored on a separate database, it’s not possible to easily evaluate the validity of a primary key.
A solution I thought up that you could try (though it may present other problems):
from leavebuddymaster.models import Company
class Department(models.Model):
company_id = models.IntegerField()
@property
def company(self):
return Company.objects.get(pk=self.company_id)
This allows you to refer to Department.company
like you normally would in your example. Setting it would just be a matter of Department.company_id = Company.pk
. Hope it helps, or at least inspires a better solution!