HASAN RAJU
HASAN RAJU

Reputation: 41

Model class django.contrib.sessions.models.Session doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

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',
            ],
        },
    },
] ```

Upvotes: 4

Views: 4481

Answers (3)

SayedMaheen
SayedMaheen

Reputation: 83

  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"

Upvotes: 4

Abpostman1
Abpostman1

Reputation: 192

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

Upvotes: 6

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477533

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.

Upvotes: 3

Related Questions