1
You can help me with this problem, I’m new to Django:
So, I’m taking an Internet course to create a distance learning platform to learn about Django. I am using the version Django 2.0.9, I have a problem during the creation of the super user, the course I am following using a version of Jango older than at the time of creation of the database socilitava the registration of the Administrator soon after. Old command:
$ python manage syncdb
But this command no longer exists (as I understand it), so I’m using the sequence of commands below:
$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py createsuperuser
I created a custom user and set as Django’s default user including the information AUTH_USER_MODEL = 'accounts.User'
in py Settings., but the field email does not appear during super user creation and error occurs below:
Nome de Usuário: gabriel
Password:
Password (again):
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/gabriel/Área de Trabalho/Curso/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/gabriel/Área de Trabalho/Curso/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/gabriel/Área de Trabalho/Curso/venv/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/gabriel/Área de Trabalho/Curso/venv/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute
return super().execute(*args, **options)
File "/home/gabriel/Área de Trabalho/Curso/venv/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/gabriel/Área de Trabalho/Curso/venv/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 179, in handle self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
**TypeError: create_superuser() missing 1 required positional argument: 'email'**
I tried to comment on the field REQUERID_FIELDS = ['email']
in the Custom User class, I deleted the database and migrated the data again, but it didn’t work, it keeps accusing the absence of the field email.
Follow Custom User model set as default:
from django.db import models
from django.contrib.auth.models import (AbstractBaseUser, PermissionsMixin,
UserManager)
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField('Nome de Usuário', max_length=30, unique=True)
email = models.EmailField('Email', unique=True)
name = models.CharField('Nome', max_length=100, blank=True)
is_active = models.BooleanField('Está ativo?', blank=True, default=True)
is_staff = models.BooleanField('É da equipe?', blank=True, default=False)
date_joined = models.DateField('Data de Cadastro', auto_now_add=True)
objects = UserManager()
USERNAME_FIELD = 'username'
REQUERID_FIELDS = ['email']
# Define a representação string do objeto
def __str__ (self):
return self.name or self.username
def get_short_name(self):
return self.username
def get_full_name(self):
return str(self)
class Meta:
verbose_name = 'Usuário'
verbose_name_plural = 'Usuários'
I was able to solve ! hahahahahah, but I can’t explain were so many commands made in the terminal.
– user128174
Anyway you have to do what I point out in my answer, if not you will have problems in the future, falling into a kind of trap. :-)
– Sidon