我有一个多态模型,其中一个孩子依赖于另一个孩子。但是,这似乎会导致迁移出现意外问题。
您可以在下面看到这些模型的简化版本。
from django.db import models
from polymorphic.models import PolymorphicModel
class Poly(PolymorphicModel):
name = models.CharField(max_length=100)
class ChildA(Poly):
some_field = models.CharField(max_length=100)
class ChildB(Poly):
some_other_field = models.CharField(max_length=100)
childa = models.ForeignKey(ChildA, on_delete=models.CASCADE)
当我运行迁移时,错误是:poly.ChildB.childa: (models.E006) The field 'childa' clashes with the field 'childa' from model 'poly.poly'.
在使用香草 Django 时,我注意到了同样的行为:
from django.db import models
class Poly(models.Model):
name = models.CharField(max_length=100)
class ChildA(Poly):
some_field = models.CharField(max_length=100)
class ChildB(Poly):
some_other_field = models.CharField(max_length=100)
childa = models.ForeignKey(ChildA, on_delete=models.CASCADE)
我究竟做错了什么?