Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Model " has more than one ForeignKey to "

Tags:

python

django

there are two Models, User And Friends. I want to make two users make friends,but it did work.

the console just said,

django.core.management.base.CommandError: System check identified some issues:

ERRORS: : (admin.E202) 'api4android.Friends' has more than one ForeignKey to 'api4android.User'.

here is the code

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

def __str__(self):  
    return self.note_name

hope my poor english makes you understand what i mean.

like image 440
twocucao Avatar asked Apr 19 '15 23:04

twocucao


1 Answers

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

like image 94
NMC Avatar answered Sep 21 '22 01:09

NMC