0

I have a model User and this other model where the admin and the users are from the same model User.

admin = models.ForeignKey(User)
users = models.ManyToManyField(User)

I get this error:

ERRORS:
admin: (fields.E304) Reverse accessor for 'admin' clashes with reverse accessor for 'users'.
HINT: Add or change a related_name argument to the definition for 'admin' or 'users'.
users: (fields.E304) Reverse accessor for 'users' clashes with reverse accessor for 'admin'.
HINT: Add or change a related_name argument to the definition for 'users' or 'admin'.
sj2001
  • 35
  • 6

2 Answers2

1

Change code like this:

admin = models.ForeignKey(User, related_name='admin_user')
users = models.ManyToManyField(User, related_name='users_user')

Also see ForeignKey related_name

Hasan Ramezani
  • 5,004
  • 24
  • 30
0

You're creating different users attributes with the same backwards relationships 'user_set', and this doesn't works.

Try it:

admin = models.ForeignKey(User)
users = models.ManyToManyField(User,related_name="+")

provide two different related_name attributes so that the backwards relationship attributes' names don't clash.

In this post, you can see the same problem: Post

The Docs:

Community
  • 1
  • 1
Paulo Pessoa
  • 2,509
  • 19
  • 30