Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'UserManage.groups'

Tags:

python

django

In my Django project I have a user_manage app.

I create a model named UserManage in my user_manage app's model.py:

from django.db import models
from django.contrib.auth.models import AbstractUser

class UserManage(AbstractUser):
    username = models.CharField(max_length=12)

Then I run:

$ python3 manage.py makemigrations

There comes the error:

ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'UserManage.groups'.
        HINT: Add or change a related_name argument to the definition for 'User.groups' or 'UserManage.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'UserManage.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'UserManage.user_permissions'.
users_management.UserManage.groups: (fields.E304) Reverse accessor for 'UserManage.groups' clashes with reverse accessor for 'User.groups'.
        HINT: Add or change a related_name argument to the definition for 'UserManage.groups' or 'User.groups'.
users_management.UserManage.user_permissions: (fields.E304) Reverse accessor for 'UserManage.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'UserManage.user_permissions' or 'User.user_permissions'.
like image 420
aircraft Avatar asked Mar 09 '18 08:03

aircraft


3 Answers

Add the following to settings.py:

AUTH_USER_MODEL = "users_management.UserManage" 

More generally,

AUTH_USER_MODEL = 'YourAppName.YourClassName'
  • YourAppName: This is the name of the app that will have the User Model
  • YourClassName: This is the name of the class used inside the models.py file
like image 91
aircraft Avatar answered Nov 17 '22 07:11

aircraft


Add this in the settings :

AUTH_USER_MODEL = 'APPNAME.User'

This way we are telling Django to use our custom model instead the default one. https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#substituting-a-custom-user-model

like image 29
AjayShelar Avatar answered Nov 17 '22 07:11

AjayShelar


Add this in the settings at the end of the code :

AUTH_USER_MODEL="users.CustomUser"
like image 6
Arnab Das Avatar answered Nov 17 '22 08:11

Arnab Das