I’m trying to make an e-mail authorization and get an error when creating superuser. What’s wrong?
application ‘www’
models.py
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.db import models
from django.utils import timezoneclass UserManager(BaseUserManager):
def _create_user(self, email, password, is_staff, is_superuser, **extra_fields):
if not email:
raise ValueError(‘Users must have an email address’)
now = timezone.now()
email = self.normalize_email(email)
user = self.model(
email=email,
is_staff=is_staff,
is_active=True,
is_superuser=is_superuser,
last_login=now,
date_joined=now,
**extra_fields
)
user.set_password(password)
user.save(using=self._db)
return userdef create_user(self, email, password, **extra_fields):
return self._create_user(email, password, False, False, **extra_fields)def create_superuser(self, email, password, **extra_fields):
user=self._create_user(email, password, True, True, **extra_fields)
return userclass User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
name = models.CharField(max_length=254, null=True, blank=True)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
last_login = models.DateTimeField(null=True, blank=True)
date_joined = models.DateTimeField(auto_now_add=True)USERNAME_FIELD = 'email' EMAIL_FIELD = 'email' REQUIRED_FIELDS = [] objects = UserManager() def get_absolute_url(self): return "/users/%i/" % (self.pk)
settings.py
INSTALLED_APPS = [
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘www’,
]ROOT_URLCONF = ‘www.urls’
AUTH_PASSWORD_VALIDATORS = [
{
‘NAME’: ‘django.contrib.auth.password_validation.UserAttributeSimilarityValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.MinimumLengthValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.CommonPasswordValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.NumericPasswordValidator’,
},
]AUTH_USER_MODEL = ‘www.User’
error
(env) isaev@web:~/plg/www$ python manage.py createsuperuser
Email: isaev@plg.ru
Traceback (most recent call last):
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 84, in _execute
return self.cursor.execute(sql, params)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py”, line 413, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: www_userThe above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “manage.py”, line 22, in
main()
File “manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/init.py”, line 401, in execute_from_command_line
utility.execute()
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/init.py”, line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/base.py”, line 330, in run_from_argv
self.execute(*args, **cmd_options)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py”, line 79, in execute
return super().execute(*args, **options)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/base.py”, line 371, in execute
output = self.handle(*args, options)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py”, line 113, in handle
error_msg = self._validate_username(username, verbose_field_name, database)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py”, line 234, in _validate_username
self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/base_user.py”, line 45, in get_by_natural_key
return self.get({self.model.USERNAME_FIELD: username})
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/manager.py”, line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 425, in get
num = len(clone)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 269, in len
self._fetch_all()
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 1308, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 53, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/sql/compiler.py”, line 1156, in execute_sql
cursor.execute(sql, params)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 98, in execute
return super().execute(sql, params)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 84, in _execute
return self.cursor.execute(sql, params)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 84, in _execute
return self.cursor.execute(sql, params)
File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py”, line 413, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: www_user