[Django]-Foreign Keys clash with related field in Django Model

6👍

The error message is quite explanatory:

class FamilyLink(models.Model):
    from_legacy = models.ForeignKey(Legacy, related_name = 'familylink_from_legacy')
    to_legacy = models.ForeignKey(Legacy, related_name = 'familylink_to_legacy')

By default, if no related_name attribute is set, the relatedname is set to familylink_set and since 2 different fields from the same relation, it causes the issues.

Read more on related_name attribute here

Leave a comment