Django throws an error: LookupError: No installed app with label 'admin'

Today after installing django-cryptography for encrypting all fields in my models using this website, this error is keep showing on my terminal after running python manage.py runserver:

  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    return check_method()
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\urls\resolvers.py", line 494, in check
    for pattern in self.url_patterns:
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\urls\resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\urls\resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\ADAMUDEE\Desktop\school\project\school\urls.py", line 23, in <module>
    path('admin/', admin.site.urls),
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\utils\functional.py", line 266, in inner
    self._setup()
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\contrib\admin\sites.py", line 595, in _setup
    AdminSiteClass = import_string(apps.get_app_config("admin").default_site)
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\apps\registry.py", line 165, in get_app_config
    raise LookupError(message)
LookupError: No installed app with label 'admin'.

I try to solve it using these answer in this question, but no one works, I also deleted sqlite in my project folder and run migrate and makemigrations again, but it does not work, is there anyone who can help please?

my settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'whitenoise.runserver_nostatic',
    'myschool',
    'crispy_forms',
    'crispy_bootstrap5',
    'bootstrap5',
    'materializecssform',
    'django_countries',
    'jsignature',
    "phonenumber_field",
]

my models:

class PrimaryAlbum(models.Model):
    name = encrypt(models.CharField(max_length=100))
    user = models.ForeignKey(User,
    on_delete=models.CASCADE)

    slug = models.SlugField(unique=True, max_length=100)


    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super().save(*args, **kwargs)
    

    def __str__(self):
        return self.name       

The first line of code in the traceback that refers back to your code is this:

While this generally implies that there is something wrong in your urls.py file, it might not be directly related to this line.

What does your complete urls.py file look like?

This is my urls.py file:

"""school URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from os import name
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('myschool.urls')),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

"""school URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from os import name
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('myschool.urls')),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

What versions of Django, Python, and django-cryptography are you using?

I’m using django= 4.1.5 and python= 3.10.0

And is the version of django-cryptography you are using compatible with that combination?

See: Installation — Django Cryptography 1.1.dev20200210060112 documentation

After deleted my virtual environment and run: runserver again, the error keep showing on my terminal sir

Did you change the versions of Python and Django that you are running to versions that are compatible with Django-cryptography?

No i deleted django-cryptography in models.py file and remove everything from fields and create a new virtual environment and install django again.

If you’re still getting an error, please post the full traceback that you are currently getting.

The error:

    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\ADAMUDEE\Desktop\school\project\school\urls.py", line 23, in <module>
    path('admin/', admin.site.urls),
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\utils\functional.py", line 266, in inner
    self._setup()
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\contrib\admin\sites.py", line 595, in _setup
    AdminSiteClass = import_string(apps.get_app_config("admin").default_site)
  File "C:\Users\ADAMUDEE\Desktop\school\myv\lib\site-packages\django\apps\registry.py", line 165, in get_app_config
    raise LookupError(message)
LookupError: No installed app with label 'admin'.

So now it gets a little tougher.

First, can you do a makemigrations and migrate?

If those don’t work, a check might help.

Beyond that, finding the source of the problem from this point will require examining pretty much everything in your code to ensure that you don’t have a syntax error or an improper reference to a package or something similar to that.

You are great sir, You are my guru, You are my pride. because I added: import django and django.setup() in the settings.py file, just to solve that problem, that is why it keeping showing that error. Thanks

But what if i want to encrypt my django fields, I’m working in a big project that required that sir.

You’ve got the same options you would always have when encountering situations like this.

  • Verify that the original problem was caused by a version incompatibility issue.

    • There’s always the chance that the issue you were seeing was the result of something else wrong, and was just revealed by that package.
  • Find an alternative package.

    • There’s always the possibility of finding a public fork that someone else has created to do what you need it to do.

    • Implement it within the database itself

  • Fix it so that it’s compatible with the versions of Python and Django you are using,

    • Hire someone to fix it for you
  • Go back to an older version of Python / Django until the package has been updated. (Which could be ā€œneverā€.)

2 Likes

Hi Ken
self = <django.apps.registry.Apps object at 0x0000023F9C4FF100>
app_label = ā€˜admin’

def get_app_config(self, app_label):
    """
    Import applications and returns an app config for the given label.

    Raise LookupError if no application exists with this label.
    """
    self.check_apps_ready()
    try:
        return self.app_configs[app_label]
    except KeyError:
        message = "No installed app with label '%s'." % app_label
        for app_config in self.get_app_configs():
            if app_config.name == app_label:
                message += " Did you mean '%s'?" % app_config.label
                break
      raise LookupError(message)

E LookupError: No installed app with label ā€˜admin’.

C:\Users\edufe\PycharmProjects\poc-report-python\venv\lib\site-packages\django\apps\registry.py:165: LookupError

I’m also having the same problem, but reading above, I saw that you mention the issue of migrations! I’m developing a data API without using a database, because I studied using the cloud. Is there a real need to do the migrate??? I can’t seem to solve this problem. I’m testing the view layer of my application.

Welcome @EduFrnds !

I suggest you open a new topic for your issue.

Note: Please don’t post images of code here. Copy/paste the code into the body of your post, between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. This forces the forum software to keep the code properly formatted. (Also do this for error messages, tracebacks, templates, and any other preformatted text.)

Also, I’m not quite sure I’m following what you’re asking here. If you’ve got an error with which you’d like assistance, please post the command you’re running, and the complete error with the traceback. (Between lines of ``` as described above.)

Tnks Ken!
Sorry buddy.