【发布时间】:2014-11-23 07:37:28
【问题描述】:
当尝试在两个外键约束上使用 unique_together 时,我收到以下错误:
CommandError: System check identified some issues:
ERRORS:
main.AuthorTag: (models.E012) 'unique_together' refers to the non-existent field 'author'.
main.AuthorTag: (models.E012) 'unique_together' refers to the non-existent field 'tag'.
在下表中
class AuthorTag(models.Model):
class Meta:
unique_together = (('tag', 'author',),)
tag = models.ForeignKey(TagIndex, on_delete=models.CASCADE),
author = models.ForeignKey(Author, on_delete=models.CASCADE),
同样的例子似乎在这里工作:Unique foreign key pairs with Django 但是我不知道为什么会出现这个错误
编辑:
将unique_together = (('tag', 'author',),) 更改为unique_together = (('tag', 'author')) 给我同样的错误。以及将元类移动到字段声明下方。
【问题讨论】:
-
不幸的是,移动元类没有效果
标签: django django-models django-database