[Django]-Django project looking for "attribute '_session_cache'"

7๐Ÿ‘

โœ…

The error AttributeError: 'SessionStore' object has no attribute '_session_cache' can stem from the database not having a django_session table. However, since you are not using a table, you would need to make sure that you donโ€™t have the 'django.contrib.sessions.middleware.SessionMiddleware' in your MIDDLEWARE_CLASSES in the projectโ€™s settings file. If it is in there, it will look for a database table which stores the sessions, causing the above error.

๐Ÿ‘คMichael B

50๐Ÿ‘

For future Googlers โ€“ I ran into this issue and the above solutions did not work for me. What did work for me was clearing/deleting my cookies in Chrome for the 127.0.0.1 URL. So go to Settings or press CMD+, then Cookies and other site data, then find 127.0.0.1 or localhost and delete those cookies. Refresh the local dev host page and the error should be gone. This has something to do with a corrupted session / cookie file.

๐Ÿ‘คelthwi

12๐Ÿ‘

Iโ€™m not sure why I started to get this error, it involved an upgrade though. I just deleted all the sessions and after logging back in all was well.

# from the shell but equivalent sql would work fine too
from django.contrib.sessions.models import Session
Session.objects.all().delete()
๐Ÿ‘คKurt

3๐Ÿ‘

Here is what worked for me. Since there is no databases in your application. Admin page looks for the database be it default. So first lets create the default databases.

Shut down your servers and run

python manage.py makemigrations
python manage.py migrate

Now create the admin or superuser for your application. Fill username and password.

python manage.py createsuperuser

Now restart your server and go the admin page

python manage.py runserver
๐Ÿ‘คHimanshu Poddar

0๐Ÿ‘

Throwed the same error for me after upgraded my wagtail versionโ€ฆ So, for me worked even simpler solution or u didnโ€™t noticed already ๐Ÿ˜€ Actually I opened the browser > F12 > Storage Tab and Delete all Cookies and all other Cached Data

๐Ÿ‘คuser596500

0๐Ÿ‘

Users facing this issue via Postman please make sure that the value in the request header for Cache-Control is no-cache.

If not then clear the cookie data for the domain.

Postman Screenshot

๐Ÿ‘คArpan Kushwaha

0๐Ÿ‘

In normal case when we use

from django.http import JsonResponse

for sending response we have no need to uses sessions.

But when we use some package such as djangorestframework we force to use sessions.

Sessions need storage place in sqllite,mysql ,โ€ฆor others
then we need run these commands:

python manage.py makemigrations
python manage.py migrate
๐Ÿ‘คMehdi Musavand

Leave a comment