问题
I've been following the Django documentation to create a custom user model.
Here is the main error - (Edit - I was asked to add the entire traceback so here it is)
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\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 "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\__init__.py", line 156, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 210, in get_model
return app_config.get_model(model_name, require_ready=require_ready)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 181, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'Hierarchy' doesn't have a 'CustomUser' model.
To make matters worse after that is shows the below error, I've done everything that the site told me to, couldn't find the answer anywhere
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Coding\TimeSheet\_OFFICIAL_\InsemiTimeSheet\Project\Infrastructure\InsemiSystem\Hierarchy\models.py", line 3, in <module>
from django.contrib.auth.admin import UserAdmin
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\admin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\forms.py", line 20, in <module>
UserModel = get_user_model()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\__init__.py", line 161, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'Hierarchy.CustomUser' that has not been installed
I have defined it in my models.py
from django.db import models
from django.contrib.auth.models import (AbstractBaseUser, BaseUserManager)
from django.contrib.auth.admin import UserAdmin
class CustomUser(AbstractBaseUser):
#I proceeded to create the User details here
I also added it correctly as the AUTH_USER_MODEL using -
AUTH_USER_MODEL = 'Hierarchy.CustomUser'
来源:https://stackoverflow.com/questions/62394664/lookuperror-app-hierarchy-doesnt-have-a-customuser-model