fields.E304 Reverse accessor clashes in Django
作者:互联网
错误信息
SystemCheckError: System check identified some issues:
ERRORS:
website.Person2Person.friend: (fields.E304) Reverse accessor for 'Person2Person.friend' clashes with reverse accessor for 'Person2Person.person'.
HINT: Add or change a related_name argument to the definition for 'Person2Person.friend' or 'Person2Person.person'.
website.Person2Person.person: (fields.E304) Reverse accessor for 'Person2Person.person' clashes with reverse accessor for 'Person2Person.friend'.
HINT: Add or change a related_name argument to the definition for 'Person2Person.person' or 'Person2Person.friend'.
解决方案
添加参数related_name
class Person2Person(models.Model):
person = models.ForeignKey(Person, related_name='person2persons')
friend = models.ForeignKey(Person, related_name='friends')
原因:
对同一个类建立多个相同的外键,会出现关系混乱,所以需要建立一个关系名称
https://stackoverflow.com/questions/41595364/fields-e304-reverse-accessor-clashes-in-django
标签:Reverse,fields,Person2Person,related,Django,person,accessor,friend,name 来源: https://blog.csdn.net/weixin_39025679/article/details/114309395