Модель Django CustomUser вызывает ошибки ленивой ссылки во время миграцииPython

Программы на Python
Ответить
Anonymous
 Модель Django CustomUser вызывает ошибки ленивой ссылки во время миграции

Сообщение Anonymous »

Я работаю над проектом Django, в котором определил модель CustomUser в приложении под названием аутентификация. Я правильно установил AUTH_USER_MODEL для ссылки на эту модель, но когда я пытаюсь выполнить миграцию, я получаю следующие ошибки:
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'authentication.customuser', but app 'authentication' doesn't provide model 'customuser'.
The field authentication.Device.user was declared with a lazy reference to 'authentication.customuser', but app 'authentication' doesn't provide model 'customuser'.
The field authentication.MoodReview.user was declared with a lazy reference to 'authentication.customuser', but app 'authentication' doesn't provide model 'customuser'.
The field authentication.PasswordResetCode.user was declared with a lazy reference to 'authentication.customuser', but app 'authentication' doesn't provide model 'customuser'.
The field authtoken.Token.user was declared with a lazy reference to 'authentication.customuser', but app 'authentication' doesn't provide model 'customuser'.


# authentication/models.py

from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
from django.db import models
from django.utils import timezone

class CustomUserManager(BaseUserManager):
def create_user(self, email, password=None, **extra_fields):
if not email:
raise ValueError("The Email field must be set")
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', 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)

class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(unique=True)
name = models.CharField(max_length=255)
# ... other fields
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)

objects = CustomUserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name']

def __str__(self):
return self.email


**Обновлена ​​конфигурация
**
AUTH_USER_MODEL = 'authentication.CustomUser'
**INSTALLED_APPS
**
INSTALLED_APPS = [
'authentication',
'django.contrib.admin',
'django.contrib.auth',
# ... other apps
]


Подробнее здесь: https://stackoverflow.com/questions/790 ... -migration
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»