1

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'
Arny Boy
  • 61
  • 2
  • 10
  • Could you please post all traceback? – ncopiy Jun 15 '20 at 22:12
  • @ncopiy added the full traceback, hope it can help identify the error – Arny Boy Jun 16 '20 at 09:25
  • have you added 'Hierarchy' to `INSTALLED_APPS` in settings.py ? https://docs.djangoproject.com/en/3.0/ref/settings/#installed-apps – ncopiy Jun 16 '20 at 09:55
  • @ncopiy yes, that was the first thing we checked and it was there. This error shouldn't be coming honestly can't understand why it's happening. – Arny Boy Jun 16 '20 at 13:24
  • try to replace `Hierarchy` by `Hierarchy.apps.HierarchyConfig` (check out you have an apps.py with `HierarchyConfig` cls) – ncopiy Jun 16 '20 at 16:08
  • @ncopiy Nope, tried that too, did not work. – Arny Boy Jun 17 '20 at 11:42
  • did you run migrations before? may be it really not registered model because there is no info about it migrations – ncopiy Jun 17 '20 at 12:36
  • @ncopiy I did that. I've tried all the basic solutions and searched everywhere on the depths Stack Overflow before asking here. – Arny Boy Jun 18 '20 at 13:52
  • @ncopiy The error itself arises when I try to migrate which is the main issue. Makemigrations and runserver seem to have the same issue. – Arny Boy Jun 18 '20 at 14:14

0 Answers0