How to work around lack of support for foreign keys across databases in Django

后端 未结 9 1405
生来不讨喜
生来不讨喜 2020-12-07 09:59

I know Django does not support foreign keys across multiple databases (originally Django 1.3 docs)

But I\'m looking for a workaround.

What doesn\'t work

9条回答
  •  我在风中等你
    2020-12-07 10:01

    A foreign key field implies that you can - query on the relationship by joining ie fruit__name - check referential integrity - ensure referential integrity upon deletes - admin raw id lookup functionality - (some more...)

    The first use case would always be problematic. Probably there are some other foreign key special cases in the codebase which also wouldn't work.

    I run a rather large django site and we are currently using a plain integerfield. For now i would think subclassing the integerfield and adding the id to object conversion would be easiest (in 1.2 that required patching some bits of django, hope that improved by now) Will let you know what solution we find.

提交回复
热议问题