Django 3.2 LookupError: модель не зарегистрирована
При попытке обновить существующий проект до Django 3.2 (с 2.2) я получал следующую ошибку:
...
from .permissionmodels import * # nopyflakes
File "/home/user/miniconda3/envs/app-web-py38-test/lib/python3.8/site-packages/cms/models/
permissionmodels.py", line 19, in <module>
User = apps.get_registered_model(user_app_name, user_model_name)
File "/home/user/miniconda3/envs/app-web-py38-test/lib/python3.8/site-packages/django/apps
/registry.py", line 273, in get_registered_model
raise LookupError(
LookupError: Model 'user_accounts.CustomUser' not registered.
Специальная модель находится в
apps/user_accounts/models.py
и выглядит так
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db import models
from .managers import CustomUserManager
class CustomUser(AbstractUser, PermissionsMixin):
username = None
email = models.EmailField(('email address'), unique=True)
# add additional fields in here
profile_picture = models.ImageField(upload_to='profile/', blank=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager()
def __str__(self):
return self.email
Установленные приложения следующие
INSTALLED_APPS = [
# this app is at the top because it defines a custom user model for the whole project
'apps.user_accounts',
'djangocms_admin_style',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
#'django.contrib.contenttypes.models.ContentType',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
#after project creation#
#Django CMS stuff
'django.contrib.sites',
'cms',
'menus',
'treebeard',
'sekizai',
'filer',
'easy_thumbnails',
'mptt',
'djangocms_link',
'djangocms_file',
'djangocms_picture',
'djangocms_video',
'djangocms_googlemap',
'djangocms_snippet',
'djangocms_style',
'djangocms_column',
'djangocms_text_ckeditor',
'djangocms_comments',
'bootstrap4',
#Aldryn News Blog
'aldryn_apphooks_config',
'aldryn_categories',
'aldryn_common',
'aldryn_newsblog',
#'aldryn_newsblog.apps.AldrynNewsBlog',
'aldryn_people',
'aldryn_translation_tools',
'absolute',
'aldryn_forms',
'aldryn_forms.contrib.email_notifications',
'captcha',
'emailit',
'parler',
'sortedm2m',
'taggit',
# this AWS S3 work (boto + django-storages)
'storages',
'widget_tweaks',
# Django Analytical for various analytics, i.e., Yandex Metrica, etc.
'analytical',
'meta',
#Custom Apps
'apps.custom_page_extensions',
'apps.custom_social_addon',
#'apps.pages',
'apps.video_uploader',
#search
#'haystack',
#bower
'djangobower',
]
AUTH_USER_MODEL = 'user_accounts.CustomUser'
Любая помощь по исправлению или устранению неполадок приветствуется.
Редактировать:
apps/user_accounts/managers.py
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import ugettext_lazy as _
class CustomUserManager(BaseUserManager):
"""
Custom user model manager where email is the unique identifiers
for authentication instead of usernames.
"""
def create_user(self, email, password, **extra_fields):
"""
Create and save a User with the given email and password.
"""
if not email:
raise ValueError(_('The Email must be set'))
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, email, password, **extra_fields):
"""
Create and save a SuperUser with the given email and password.
"""
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_active', True)
if extra_fields.get('is_staff') is not True:
raise ValueError(_('Superuser must have is_staff=True.'))
if extra_fields.get('is_superuser') is not True:
raise ValueError(_('Superuser must have is_superuser=True.'))
return self.create_user(email, password, **extra_fields)