TypeError: UserManager.create_superuser() missing 4 required positional arguments: ‘user_name’, ‘first_name’, ‘last_name’, and ‘phone_number’
This is the error i get when i run ‘python manage.py createsuperuser’ even though i have specified the arguments in the REQUIRED_FIELDS, the command prompt does not give me an option to enter the username firstname, last name and phonenumber. I have seen that many people have asked the same question in different forums, i have tried the different solutions provided but i have not been successful. Kindly help if you can. The following is my code in models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
class UserManager(BaseUserManager):
def create_user(
self,
email,
user_name,
first_name,
last_name,
phone_number,
password,
**other_fields
):
if not email:
raise ValueError('User must have an email address')
if not user_name:
raise ValueError('User must have a username')
email = self.normalize_email(email),
user = self.model(
email=email,
user_name=user_name,
first_name=first_name,
last_name=last_name,
phone_number=phone_number,
**other_fields
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(
self,
email,
user_name,
first_name,
last_name,
phone_number,
password,
**other_fields
):
if other_fields.get('is_staff') is not True:
raise ValueError('Super User must be a staff')
if other_fields.get('is_superuser') is not True:
raise ValueError('Super User must be a superuser')
other_fields.setdefault('is_staff', True)
other_fields.setdefault('is_superuser', True)
other_fields.setdefault('is_admin', True)
other_fields.setdefault('is_active', True)
return self.create_user(
self,
email,
user_name,
first_name,
last_name,
phone_number,
password,
**other_fields
)
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=150, unique = True, blank=True)
user_name = models.CharField(max_length=50, unique = True)
first_name = models.CharField(max_length=50, blank=True)
last_name = models.CharField(max_length=50, blank=True)
phone_number = models.CharField(max_length=30, blank=True)
date_joined = models.DateTimeField(auto_now_add=True)
last_login = models.DateTimeField(auto_now_add=True)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
objects = UserManager()
USERNAME_FIELD = 'email'
RUQUIRED_FIELDS = [
'user_name',
'first_name',
'last_name',
'phone_number'
]
def __str__(self):
return self.email
in the settings.py i have the following also
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users',
]
AUTH_USER_MODEL = 'users.User'
This is the full error log:
Traceback (most recent call last):
File "D:\Dev\sixteen\liquormatic\manage.py", line 22, in <module>
main()
File "D:\Dev\sixteen\liquormatic\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "D:\Dev\sixteen\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "D:\Dev\sixteen\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Dev\sixteen\Lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Dev\sixteen\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 88, in execute
return super().execute(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Dev\sixteen\Lib\site-packages\django\core\management\base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Dev\sixteen\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 233, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(
TypeError: UserManager.create_superuser() missing 4 required positional arguments: 'user_name', 'first_name', 'last_name', and 'phone_number'
(sixteen) D:\Dev\sixteen\liquormatic>