Django/South:在多对多自关系上为中间模型设置相关名称参数的正确方法是什么?
这与a有关,但是,由于我目前只是对一个应用程序进行原型设计/由于时间限制,我决定只删除相关表并重置迁移历史记录 以下是相关模型/字段:Django/South:在多对多自关系上为中间模型设置相关名称参数的正确方法是什么?,django,django-models,django-south,Django,Django Models,Django South,这与a有关,但是,由于我目前只是对一个应用程序进行原型设计/由于时间限制,我决定只删除相关表并重置迁移历史记录 以下是相关模型/字段: class Person(models.Model): nominator = models.ManyToManyField('self', symmetrical=False, verbose_name=_('nominator'), through='Nomination', null=True
class Person(models.Model):
nominator = models.ManyToManyField('self', symmetrical=False,
verbose_name=_('nominator'), through='Nomination', null=True,
blank=True)
class Nomination(models.Model):
nominee = models.ForeignKey(Person)
nominator = models.ForeignKey(Person)
但是,这甚至不会生成初始迁移:
$ ./manage.py schemamigration nominations --initial
CommandError: One or more models did not validate:
nominations.nomination: Accessor for field 'nominee' clashes with related field 'Person.nomination_set'. Add a related_name argument to the definition for 'nominee'.
nominations.nomination: Accessor for field 'nominator' clashes with related field 'Person.nomination_set'. Add a related_name argument to the definition for 'nominator'.
我按照说明向提名
模型上的提名人
和提名人
字段添加了一个相关的\u name
参数,如下所示:
class Nomination(models.Model):
nominee = models.ForeignKey(Person, related_name=_('nominator'))
nominator = models.ForeignKey(Person, related_name=_('nominee'))
这给了我一个不同的错误:
$ ./manage.py schemamigration nominations --initial
CommandError: One or more models did not validate:
nominations.nomination: Accessor for field 'nominee' clashes with m2m field 'Person.nominator'. Add a related_name argument to the definition for 'nominee'.
nominations.nomination: Reverse query name for field 'nominee' clashes with m2m field 'Person.nominator'. Add a related_name argument to the definition for 'nominee'.
我不知道从现在开始该怎么办。我有种感觉,我已经忘记了一些东西,比如
Person
模型,但我不确定这可能是什么,因为Django/South文档在处理这种关系时都不是很积极。只是使用不同的名称,而不是字段名称。比如提名人和被提名人
我将此注释移至答案,这样问题就不再没有答案了。只需使用字段名称以外的其他名称即可。比如提名人和被提名人
我将此注释移至答案,这样问题就不再没有答案。只需使用字段名称以外的其他名称即可。类似于
个人提名人
和个人提名人
哦,我明白了。我确信这与Person
模型本身的字段有关。现在确实有道理了。非常感谢!只需使用字段名称以外的其他名称。类似于个人提名人
和个人提名人
哦,我明白了。我确信这与Person
模型本身的字段有关。现在确实有道理了。非常感谢!