为什么我要来:
Error: One or more models did not validate:
test.test: "unique_together" refers to slug. This is not
in the same model as the unique_together statement.
test.test: "unique_together" refers to version. This is not
in the same model as the unique_together statement.
我有这样的模型定义:
class SlugVersion(models.Model):
class Meta:
abstract = True
unique_together = (('slug', 'version'),)
slug = models.CharField(db_index=True, max_length=10, editable=False)
version = models.IntegerField(db_index=True, editable=False)
class Base(SlugVersion):
name = models.CharField(max_length=10)
class Test(Base):
test = models.IntegerField()
我有Django 1.3。
答案 0 :(得分:2)
Django似乎是bug。
答案 1 :(得分:0)
这是因为Test
使用multi-table inheritance从Base
继承,它为这两个模型创建了单独的表,并将它们与OneToOne关系链接起来。因此,slug
和version
字段仅存在于Base
表中,而不存在于测试表中。
您是否需要Base
非抽象?换句话说,您会创建任何实际的Base
个对象吗?如果将其设置为抽象,则此错误消失。