小编evr*_*rom的帖子

'unique_together' 指的是不存在的字段

尝试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'.
Run Code Online (Sandbox Code Playgroud)

在下表中

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),
Run Code Online (Sandbox Code Playgroud)

同样的例子似乎在这里工作:Unique外键对与 Django 但我不明白为什么我会收到这个错误

编辑:改变unique_together = (('tag', 'author',),)unique_together = (('tag', 'author'))给我同样的错误。以及将元类移动到字段声明下方。

django django-models django-database

5
推荐指数
1
解决办法
4701
查看次数

标签 统计

django ×1

django-database ×1

django-models ×1