Django getting error when trying to save AbstractUser model

I want to save this AbstractUser in my model.

#app_name members
#models.py
class User(AbstractUser):
        is_student = models.BooleanField(default=False)
        is_teacher = models.BooleanField(default=False)

settings.py

INSTALLED_APPS = [
 #defult django app...
 #others app....
 'members',

]

AUTH_USER_MODEL = 'members.User'

getting this error when clicking on save before go makemigartions and migrate

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

ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'auth.User.groups' clashes with reverse accessor for 'members.User.groups'.        
        HINT: Add or change a related_name argument to the definition for 'auth.User.groups' or 'members.User.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'auth.User.user_permissions' clashes with reverse accessor for 'members.User.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'auth.User.user_permissions' or 'members.User.user_permissions'.
members.User.groups: (fields.E304) Reverse accessor for 'members.User.groups' clashes with reverse accessor for 'auth.User.groups'.     
        HINT: Add or change a related_name argument to the definition for 'members.User.groups' or 'auth.User.groups'.
members.User.user_permissions: (fields.E304) Reverse accessor for 'members.User.user_permissions' clashes with reverse accessor for 'auth.User.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'members.User.user_permissions' or 'auth.User.user_permissions'.

How to solve this error and why getting this error? I also keep my all foreignkey fileds unique by using related_name

The error was for two reason:

  1. I was using default Django User in my all models author = models.ForeignKey(User,on_delete=models.CASCADE,max_length=100, related_name='author') it should be author = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,max_length=100, related_name='author')

  2. I was using wrong name for AUTH_USER_MODEL in my settings.py

1 Like

This should help you with when to use AUTH_USER_MODEL and when to use get_user_model()