Typeerror: Create_superuser() Missing 1 Required Positional Argument: 'profile_picture'
I get the following error after adding the profile_picture field: TypeError: create_superuser() missing 1 required positional argument: 'profile_picture' This profile_picture fiel
Solution 1:
Well, you need to create the create_superuser
function as well:
classUserManager(BaseUserManager):
defcreate_user(self, email, full_name, profile_picture, password=None, is_admin=False, is_staff=False, is_active=True):
ifnot email:
raise ValueError("User must have an email")
ifnot password:
raise ValueError("User must have a password")
ifnot full_name:
raise ValueError("User must have a full name")
user = self.model(
email=self.normalize_email(email)
)
user.full_name = full_name
user.set_password(password) # change password to hash
user.profile_picture = profile_picture
user.admin = is_admin
user.staff = is_staff
user.active = is_active
user.save(using=self._db)
return user
defcreate_superuser(self, email, full_name, profile_picture, password=None, **extra_fields):
ifnot email:
raise ValueError("User must have an email")
ifnot password:
raise ValueError("User must have a password")
ifnot full_name:
raise ValueError("User must have a full name")
user = self.model(
email=self.normalize_email(email)
)
user.full_name = full_name
user.set_password(password)
user.profile_picture = profile_picture
user.admin = True
user.staff = True
user.active = True
user.save(using=self._db)
return user
Good Luck!
Solution 2:
You can add username
to REQUIRED_FIELDS. After that python manage.py createsuperuser
asks for username field and works.
REQUIRED_FIELDS = ['full_name', 'gender', 'username]
Solution 3:
I had the same problem, it turned out that in the list named REQUIRED_FIELDS was misnamed. That list tells the django framework to ask for name as well during the creation. Because it is not asking and you've made it necessary. I hope it helps, best of luck
Solution 4:
Better to create a class in 0001.initial.py file of migrations. Define a class with all required fields for login and provide dependencies and operations blocks empty.That's it
Solution 5:
Make a 0001_initial.py file inside the migrations folder and follow up the below code it will work...
from django.db import migrations
from api.user.models import CustomUser
classMigration(migrations.Migration):
defseed_data(apps, schema_editor):
user = CustomUser(name='name',
email='mail@gmail.com',
is_staff=True,
is_superuser=True,
phone='987654321',
gender='Male'
)
user.set_password('anypassword')
user.save()
dependencies=[
]
operations=[
migrations.RunPython(seed_data),
]
Post a Comment for "Typeerror: Create_superuser() Missing 1 Required Positional Argument: 'profile_picture'"