4

when I try to log-in Django admin panel using my superuser id & pass a runtime-error appears"Model class django.contrib.sessions.models.Session doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS." What to do ?

I have tried adding 'django.contrib.sites', in INSTALLED_APPS & SITE_ID = 1 as shown in some solutions but it didn't work.

my settings.py looks like this

INSTALLED_APPS = [
    'newsfeed',
    'user_profile',
    'django.contrib.sites',
    'Alumni_Portal.apps.AlumniPortalConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    #'django.contrib.sites',
    'django_extensions',
    'django.contrib.contenttypes',
    #'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]
SITE_ID = 1

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'NSU_Alumni_Portal.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
] ```
1
  • 2
    You should add 'django.contrib.sessions', to the INSTALLED_APPS (uncomment). Aug 16, 2019 at 22:20

3 Answers 3

6

Had same issue. Adding 'django.contrib.sessions' didn't work I noticed when switching to Edge didn't raise the error. Back to Chrome with clearing cookies and temps did the trick

1
  • 1
    This was my issue all along. Swapped to a private window in my browser and bang, the issue is gone. Seems if you uninstall the sessions app in a project where it has been launched at least once in a browser, it causes you to have to clear your cookies and probably session data.
    – Blixem
    Nov 10, 2021 at 19:46
4
  1. Right click and inspect your site
  2. Select Application from (Elements, Console, Sources, Network, Applications)
  3. "Clear site data"
  4. It will work if you removed the sessions app and any other reference to sessions
  5. Otherwise you have to add/uncomment "django.contrib.sessions"
2
  • Adding "django.contrib.sessions" did the trick for me, thank you very much
    – Moritz
    Jul 6, 2022 at 13:16
  • Yes, this was a cache problem. I removed the sessions app after running once. Clearing the cache solved the issue. Mar 3 at 16:56
3

One of your models is referring to the Session model in the django.contrib.sessions app, so you need to install it, by adding it (or uncommenting it) in the INSTALLED_APPS:

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

    'newsfeed',
    'user_profile',
    'Alumni_Portal.apps.AlumniPortalConfig',
]

Usually the non-standard apps are placed after the ones in the django.contrib module.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.