[Fixed]-Django Model " has more than one ForeignKey to "

36👍

In your admin.py you have to specify fk_name to each relation.
Example:

class FriendshipInline(admin.TabularInline):
    model = Friendship
    fk_name = "user"

More info:
Django Docs

👤NMC

0👍

Change it to this

class Friends(models.Model):
    user = models.ForeignKey(User, null=True)
    friend = models.ForeignKey(User, null=True, related_name='friend')
    note_name = models.CharField(max_length=20)

def __str__(self):  
    return self.note_name

Leave a comment