错误信息
SystemCheckError: System check identified some issues:
ERRORS:
website.Person2Person.friend: (fields.E304) Reverse accessor for 'Person2Person.friend' *es 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' *es 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://*.com/questions/41595364/fields-e304-reverse-accessor-*es-in-django