LookupError: there is no installed application with the label 'user'

I get LookupError: No installed app with label 'user'when I run the following code:

from django.db import models

from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin

class UserManager(BaseUserManager):

    def _create_user(self, username, email, password, is_staff, is_superuser,
            **extra_fields):

        if not email:
            raise ValueError('El email debe de ser obligatorio')

        email = self.normalize_email(email)
        user = self.model(username=username, email=email, is_activate=True,
                is_staff=is_staff, is_superuser=is_superuser, **extra_fields)
        user.set_password(password)
        user.save(using = self.db)
        return user

    def create_user(self, username, email, password=None,
            **extra_fields):    
        return self._create_user(username, email, password, False, False, **extra_fields)

    def create_superuser(self, username, email, password,
            **extra_fields):
        return self._create_user(username, email, password, True, True, **extra_fields)

class User(AbstractBaseUser, PermissionsMixin):

    username = models.CharField(max_length=50, unique=True)
    email = models.EmailField(max_length=50, unique=True)
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    avatar = models.URLField()


    objects = UserManager()

    is_activate = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)

    USERNAME_FIELD = 'username'
    REQUIRE_FIELDS = ['email']

    def get_short_name(self):
        return self.username

The source of the error is unclear, why is this error presented?

In particular, which line is looking for the user’s label and why doesn’t it find what it is looking for?

+4
source share
1 answer

You need to set AUTH_USER_MODELin settings.py to the user model of the user

as well as an application that has a user model of user INSTALLED_APPSin settings.py

+4
source

Source: https://habr.com/ru/post/1607314/


All Articles