Why is meta class giving an error for abstract?

25 views Asked by At

When I added abstract = True to this code:

customUser(AbstractBaseUser,PermissionsMixin):
    id = models.autofield(primary_key = True)

    class Meta:
        verbose_name = 'User'
        verbose_name_plural = 'Users'
        abstract = True

it is returing this error:

django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model core.CustomUser' that has not been installed but settings.py is properly set.

Why does this happen?

2

There are 2 answers

0
Pycm On

abstract = True means, it will not create a db table for that model. So, it can't be use as user model or use for authentication, login.

Reference

0
willeM_ Van Onsem On

It makes no sense to refer to a user model that is abstract. Abstract means that there is no table for that model. Typically abstract models are used to be inherited in other (non-abstract i.e. concrete) models.

So if you would use an abstract model as user model, then how would you register (i.e. create) new users, fetch these users to log in, etc.?

You thus should always refer to a non-abstract model as AUTH_USER_MODEL [Django-doc].