{"record":{"id":"c6b2baebb9f626ac","repo":"django/django","slug":"auth-user-model-refers-to-model-that-has-not-b","errorCode":null,"errorMessage":"AUTH_USER_MODEL refers to model '%' that has not been installed","messagePattern":"AUTH_USER_MODEL refers to model '%' that has not been installed","errorType":"exception","errorClass":"ImproperlyConfigured","httpStatus":null,"severity":"critical","filePath":"django/contrib/auth/__init__.py","lineNumber":272,"sourceCode":"            user = None\n    await user_logged_out.asend(sender=user.__class__, request=request, user=user)\n    await request.session.aflush()\n\n    _set_auth_user(request)\n\n\ndef get_user_model():\n    \"\"\"\n    Return the User model that is active in this project.\n    \"\"\"\n    try:\n        return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)\n    except ValueError:\n        raise ImproperlyConfigured(\n            \"AUTH_USER_MODEL must be of the form 'app_label.model_name'\"\n        )\n    except LookupError:\n        raise ImproperlyConfigured(\n            \"AUTH_USER_MODEL refers to model '%s' that has not been installed\"\n            % settings.AUTH_USER_MODEL\n        )\n\n\ndef get_user(request):\n    \"\"\"\n    Return the user model instance associated with the given request session.\n    If no user is retrieved, return an instance of `AnonymousUser`.\n    \"\"\"\n    from .models import AnonymousUser\n\n    user = None\n    try:\n        user_id = _get_user_session_key(request)\n        backend_path = request.session[BACKEND_SESSION_KEY]\n    except KeyError:\n        pass","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/auth/__init__.py#L254-L290","documentation":"Raised as ImproperlyConfigured by get_user_model() when the label.model parses but the model cannot be found, i.e. apps.get_model() raises LookupError. This means the referenced app/model is not installed or does not define that model.","triggerScenarios":"AUTH_USER_MODEL = 'accounts.User' but 'accounts' is not in INSTALLED_APPS, or the User model was renamed/removed. Fires at the first get_user_model() call (auth imports, migrations, admin loading).","commonSituations":"Swapping to a custom user model in an app that is not yet in INSTALLED_APPS; typos in app_label or model name; migrations run before the custom user app is installed; circular import causing the app not to be ready.","solutions":["Add the app containing the custom User model to INSTALLED_APPS (before django.contrib.auth when swapping mid-project).","Correct the app_label/model_name spelling to match the installed app and model class.","Ensure migrations for the custom user app exist and run first; follow the custom-user migration docs if swapping in an existing project."],"exampleFix":"// before: app not installed\nAUTH_USER_MODEL = \"accounts.User\"\n# INSTALLED_APPS lacks \"accounts\"\n\n// after: install the app\nINSTALLED_APPS = [..., \"accounts\", \"django.contrib.auth\", ...]\nAUTH_USER_MODEL = \"accounts.User\"","handlingStrategy":"validation","validationCode":"# Confirm the app and model resolve before the first request.\nfrom django.apps import apps\nfrom django.conf import settings\n\ndef validate_user_model():\n    app_label, model_name = settings.AUTH_USER_MODEL.split('.')\n    if app_label not in {c.label for c in apps.get_app_configs()}:\n        raise ImproperlyConfigured(f'App {app_label!r} not in INSTALLED_APPS')\n    cfg = apps.get_app_config(app_label)\n    if not cfg.models:\n        apps.get_model(app_label, model_name)  # raises LookupError if missing","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List the custom-user app in INSTALLED_APPS, before django.contrib.auth when swapping.","Run `manage.py check` in CI to catch an unresolvable AUTH_USER_MODEL early.","When swapping the user model in an existing project, follow Django's custom-user migration guide exactly."],"tags":["authentication","configuration","user-model","installed-apps","improperly-configured"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}