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

后端 未结 4 1962
悲哀的现实
悲哀的现实 2020-12-01 10:36

I have 2 models for 2 different databases:
Databases were created manually but it should change nothing.

class LinkModel(models.Model): # in \'urls\' d         


        
4条回答
  •  半阙折子戏
    2020-12-01 11:14

    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.

提交回复
热议问题