ERROR - DJANGO 2.0.9 - TypeError: create_superuser () missing 1 required positional argument: 'email'

1

Can you help me with the following problem, I'm new to Django:

So, I'm doing a course on the internet to set up a distance learning platform to learn about Django. I'm using the Django 2.0.9 version, I'm having trouble creating the super user, the course I'm following using a version of django older than the time the database was created, I used to register the Administrator shortly after. Old command:

$ python manage syncdb

But this command no longer exists (as I understand it), so I'm using the following script:

$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py createsuperuser

I have created a custom user and defined it as the default Django user including the AUTH_USER_MODEL = 'accounts.User' information in settings.py , but the email field does not appear during super user creation and occurs the error 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 the REQUERID_FIELDS = ['email'] field in the Custom User class, deleted the database and migrated the data again, but it did not work, it continues to accuse the absence of the email field. >

Follow the Custom User template set as the 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'
    
asked by anonymous 15.10.2018 / 01:54

1 answer

0

In the User class definition, where you inform USER_NAME_FIELD, add the EMAIL_FIELD, like this:

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()

    EMAIL_FIELD = 'email'  # ====> Acrescente essa linha
    USERNAME_FIELD = 'username'
    REQUERID_FIELDS = ['email']
    .... 
    
15.10.2018 / 15:58