«AUTH_USER_MODEL относится к модели «%s», которая не была установлена » % настройки.AUTH_USER_MODEL, который не был установлен

#django #django-models #django-rest-framework #django-views

Вопрос:

Прошло уже несколько дней, я пытаюсь найти решение своей проблемы, но не могу этого сделать, я попытался расширить существующую модель пользователя, а затем объявил об этом в настройках. Однако, когда я пытаюсь выполнить миграцию, мой django не может распознать приложение фрагментов, которое я создал. Вот мой код:

 from django.db import models
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles
from django.contrib.auth.models import (
    AbstractBaseUser, BaseUserManager, PermissionsMixin
)
from django.contrib.auth import get_user_model
from django.conf import settings # new

LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted([(item, item) for item in get_all_styles()])

User = get_user_model()

class trueLinenos(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(linenos=True)

class falselinenos(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(linenos=False)

# Create your models here.
class Snippet(models.Model):
    created=models.DateTimeField(auto_now_add=True)
    title=models.CharField(max_length=100, blank=True, default='')
    code=models.TextField()
    linenos = models.BooleanField(default=False)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)
    ##questions why we need related_name here?
    users=models.ForeignKey(settings.AUTH_USER_MODEL,related_name='snippets',on_delete=models.CASCADE)
    highlighted=models.TextField()

    objects=models.Manager()
    truelinenos=trueLinenos()
    falselinenos=falselinenos()

    class Meta:
        ordering = ['created']


class UserManager(BaseUserManager):
    def create_user(self, username, email, password=None):
        user=self.model(username=username, email=email)
        #user.set_password(password)
        user.set_password(password)
        user.save()

        return user
    
    def create_superuser(self, username, email, password=None):
        user=self.model(username=username, email=email)
        user.is_superuser=True
        user.set_password(password)
        user.save()
        return user 

    
  
class User(AbstractBaseUser, PermissionsMixin):
   
    username = models.CharField(db_index=True, max_length=255, unique=True)

    email = models.EmailField(db_index=True, unique=True)


    is_active = models.BooleanField(default=True)

    
    is_staff = models.BooleanField(default=False)

    
    created_at = models.DateTimeField(auto_now_add=True)

  
    updated_at = models.DateTimeField(auto_now=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

   
    objects = UserManager()

    def __str__(self):
        """
        Returns a string representation of this `User`.

        This string is used when a `User` is printed in the console.
        """
        return self.email

 

вот код для моего setting.py файл

 """
Django settings for tutorial project.

Generated by 'django-admin startproject' using Django 3.1.4.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "3isudtelx0#rvn(s*1!vsvcups8=^p$h$)2%uaw(ph_%b$zxgg"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'rest_framework',
    'django_filters',
    'snippets',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles']



MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'tutorial.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'tutorial.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}


AUTH_USER_MODEL = 'snippets.User'

 

can someone help me to figure out the mistake I made?
regards,