I'm using Python 3.9 and Django 3.2. Here is my folder structure
cbapp
- settings.py
models
- __init__.py
- custom_user.py
- manage.py
Here's what my customer_user.py file looks like
$ cat models/custom_user.py
import uuid
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
pass
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Additionally, I have configured this in my settings.py file
AUTH_USER_MODEL = 'models.CustomUser'
However, when I run "python manage.py makemigrations", I get this error
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'models.CustomUser' that has not been installed
I have no idea what this means. I have this in my settings.py file
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cbapp',
]
...
AUTH_USER_MODEL = 'models.CustomUser'
CodePudding user response:
According to Django doc, to substitute a custom User model
You create your custom user model ( you did it already )
In
settings.py
, point AUTH_USER_MODEL to it ( the model, you create above ) like this:AUTH_USER_MODEL = 'myapp.MyUser'
You error is here : instead of
AUTH_USER_MODEL = 'models.CustomUser'
writeAUTH_USER_MODEL = 'cbapp.CustomUser'
NB : Don't point your models file but your app_name
then the model_name
.