Django Bi-directional ManyToMany - How to prevent table creation on second model?

前端 未结 4 662
情书的邮戳
情书的邮戳 2021-01-31 05:51

I have two models, each has a shared ManyToMany, using the db_table field. But how do I prevent syncdb from attempting to create the shared table, for the second model?

4条回答
  •  旧巷少年郎
    2021-01-31 06:14

    I also found this solution, which worked perfectly for me :

    class Test1(models.Model):
        tests2 = models.ManyToManyField('Test2', blank=True)
    
    class Test2(models.Model):
        tests1 = models.ManyToManyField('Test1', through=Test1.tests2.through, blank=True)
    

提交回复
热议问题