[Python] KeyError: 'admin' even when admin is under installed apps

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am getting an error that I am having trouble fixing. When I try to run the server or makemigrations to migrate it says the admin app is not there. However I have checked the installed apps under the settings file and it is there. I don't understand why I am getting this error.

    INSTALLED_APPS = [
    # Django Apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',


    (env) PS C:\Users\inr69\Documents\GitHub\afreebird_website_3.0> python manage.py makemigrations
    C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\config\settings
    C:\Users\inr69\Documents\GitHub\afreebird_website_3.0
    LOADING: C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\.env
    ENV FILE LOADED
    Traceback (most recent call last):
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\apps\registry.py", line 158, in get_app_config
    return self.app_configs[app_label]
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^
    KeyError: 'admin'
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\manage.py", line 17, in <module>
    execute_from_command_line(sys.argv)
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\core\management\base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\core\management\base.py", line 454, in execute
    self.check()
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\core\management\base.py", line 486, in check
    all_issues = checks.run_checks(
    ^^^^^^^^^^^^^^^^^^
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\core\checks\urls.py", line 136, in check_custom_error_handlers
    handler = resolver.resolve_error_handler(status_code)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\urls\resolvers.py", line 732, in resolve_error_handler
    callback = getattr(self.urlconf_module, "handler%s" % view_type, None)
    ^^^^^^^^^^^^^^^^^^^
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\utils\functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
    ^^^^^^^^^^^^^^^^^^^
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\urls\resolvers.py", line 711, in urlconf_module
    return import_module(self.urlconf_name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\inr69\.pyenv\pyenv-win\versions\3.12.8\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 999, in exec_module
    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\config\urls.py", line 9, in <module>
    path('afbadmin/', admin.site.urls),
    ^^^^^^^^^^^^^^^
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\utils\functional.py", line 251, in inner
    self._setup()
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\contrib\admin\sites.py", line 605, in _setup
    AdminSiteClass = import_string(apps.get_app_config("admin").default_site)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\inr69\Documents\GitHub\afreebird_website_3.0\env\Lib\site-packages\django\apps\registry.py", line 165, in get_app_config
    raise LookupError(message)
    LookupError: No installed app with label 'admin'.


    I tried to run the server using daphne -e ssl:8000:privateKey=server.key:certKey=server.crt config.asgi:application but got the same error.

    This is for the websockets as for video calls. I just need it to run without this error. To just run as normally.

    I tried to delete all migrations which I did but now cannot makemigrations because I get the same error. I also deleted all pycache files to no avail. I've tried adding app labels to my models but I am pretty sure it doesn't have much to do with the admin.

    Continue reading...

Compartilhe esta Página