P.S: I'm new to Django, hope anyone can help me out:-)
I had created a customer user model to override the already existing one Django provides, but I wanted to make a lot of changes on it including changing the name of that custom model, like completely starting over in another app but in the same project, looks like I'm getting errors while trying to do migrations.
Thought that if I changed the database and performed migrations it would work but it didn't, they say this:
ERRORS:
user.UserAccountModel.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'user.UserAccountModel.groups' clashes with reverse accessor for 'userAccount.UserModel.groups'.
HINT: Add or change a related_name argument to the definition for 'user.UserAccountModel.groups' or 'userAccount.UserModel.groups'.
user.UserAccountModel.user_permissions: (fields.E304) Reverse accessor 'Permission.user_set' for 'user.UserAccountModel.user_permissions' clashes with reverse accessor for 'userAccount.UserModel.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'user.UserAccountModel.user_permissions' or 'userAccount.UserModel.user_permissions'.
userAccount.UserModel.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'userAccount.UserModel.groups' clashes with reverse accessor for 'user.UserAccountModel.groups'.
HINT: Add or change a related_name argument to the definition for 'userAccount.UserModel.groups' or 'user.UserAccountModel.groups'.
userAccount.UserModel.user_permissions: (fields.E304) Reverse accessor 'Permission.user_set' for 'userAccount.UserModel.user_permissions' clashes with reverse accessor for 'user.UserAccountModel.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'userAccount.UserModel.user_permissions' or 'user.UserAccountModel.user_permissions'.
Helper: My first custom model was 'UserModel' in userAccount app and now i changed it to 'UserAccountModel' in user app
Is it maybe not allowed to change the Custom user model's name in django once you have already made migrations and established as you default user model?
Here is my models.py code:
from django.db import models
from django.contrib.auth.models import AbstractBaseUser,PermissionsMixin
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import gettext_lazy as _
class UserManager(BaseUserManager):
def create_user(self, email, password, **extra_fields):
if email is None:
raise ValueError(_('Email field is required'))
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, email, password, **extra_fields):
"""
Create and save a SuperUser with the given email and password.
"""
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_active', True)
if extra_fields.get('is_staff') is not True:
raise ValueError(_('Superuser must have is_staff=True.'))
if extra_fields.get('is_superuser') is not True:
raise ValueError(_('Superuser must have is_superuser=True.'))
if extra_fields.get('is_active') is not True:
raise ValueError(_('Superuser must have is_active=True.'))
return self.create_user(email, password, **extra_fields)
class UserAccountModel(AbstractBaseUser,PermissionsMixin):
USER_ROLE=(
('admin','Admin'),
('talent','Talent'),
('employer','Employer'),
)
# Talent, employer
email = models.EmailField(_('email address'),unique=True)
first_name = models.CharField(_('first name'), max_length=100)
last_name = models.CharField(_('last name'), max_length=100)
role = models.CharField(choices=USER_ROLE,max_length=10,default=USER_ROLE[2][1])
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
is_verified = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
USERNAME_FIELD='email'
# REQUIRED_FIELDS=[]
objects = UserManager()
def __str__ (self):
return self.email
def tokens(self):
return ''