Brief description of the problem
In django, when creating a new User class and inheriting from the AbstractUser class, the following error occurs.
ERRORS: auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'User.groups'.
from django.db import models
from ..db.base_model import BaseModel
from django.contrib.auth.models import AbstractUser
# Create your models here.
class User(AbstractUser, BaseModel):
'''User Model Class'''
class Meta:
db_table = 'df_user'
verbose_name = 'User'
verbose_name_plural = 'User'
Cause of error
This is because the new user class conflicts with Django’s own user class
Solutions
Add a line of configuration in the global setting file and use the custom model class:
AUTH_USER_MODEL = 'user.User' # where user is the app name and User is the model class name
Similar Posts:
- [Solved] DjangoORM Run python manage.py makemigrations Error: no changes detected
- Django admin Error: ‘WSGIRequest’ object has no attribute ‘user’
- django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named ‘M…
- python Warning: OverflowError: Python int too large to convert to C long
- How to Solve Django xadmin installation Error [7 Types of Errors]
- Django: How to Convert Models object to JSON
- “No module named context_processors”
- [Solved] Django Error: – no such table: main.auth_user__old
- How to Solve Django Error: No such column: xxx
- Django @csrf_exempt Cannot work in class view (Django @csrf_exempt not working in class View)