As in question 36046698, I have a CustomUser model defined in models.py.
I would like it to appear in the Authentication & Authorization section in Django Admin.
I tried adding app_label = 'auth' as suggested, i.e.
class CustomUser(AbstractUser):
class Meta:
app_label = 'auth'
When I do that, my app won’t start, and errors out like so:
Traceback (most recent call last):
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/apps/config.py", line 178, in get_model
return self.models[model_name.lower()]
KeyError: 'customuser'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 157, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/apps/registry.py", line 211, in get_model
return app_config.get_model(model_name, require_ready=require_ready)
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/apps/config.py", line 180, in get_model
raise LookupError(
LookupError: App 'myapp' doesn't have a 'CustomUser' model.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
....
File "/Users/paul/myapp/myapp/admin.py", line 3, in <module>
from django.contrib.auth.admin import UserAdmin
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/contrib/auth/admin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 21, in <module>
UserModel = get_user_model()
File "/Users/paul/myapp/.direnv/python-3.8.5/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 161, in get_user_model
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'myapp.CustomUser' that has not been installed
In settings.py, I have
AUTH_USER_MODEL = 'myapp.CustomUser'
If I comment out that line, the server starts, but page loads fail with:
ValueError: Cannot create form field for 'user' yet, because its related model
'CustomUser' has not been loaded yet
This seems to be the same crash as question 62394664.