[Django]-Why "no such table: django_session" when trying to use admin?

4👍

path to sqlite is usually the problem.

'NAME': 'c:/path/to/sqlite.db'

4👍

Make migrations will solve the problem.

Run below commands:

python ./manage.py migrate

python ./manage.py makemigrations

2👍

Try this

from os.path import dirname, abspath
ROOT = dirname(abspath(__file__)).replace('\\', '/') + '/'

print "self.__name__: " + __name__
print "self.__file__: " + __file__
print "ROOT: " + ROOT

import django
print "django.__path__: " 
print (django.__path__)

# Contact for error messages etc. - dont forget the ',' after the first entry

ADMINS = (('dev', 'dev@example.com'),)
MANAGERS = ADMINS

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',        
'NAME': ROOT + 'project.db',                      
    'USER': '',    'PASSWORD': '',
    'HOST': '',    'PORT': '',                      
}
}

and check if you need + ‘/’ + before the database name for your operating system.

1👍

SESSION_ENGINE it’s using django.contrib.sessions.backends.db by default and that’s make you need to :

  1. put django.contrib.sessions in INSTALLED_APPS list variable in settings.py
  2. you must migrate your database

if you don’t want to do that, just put SESSION_ENGINE to django.contrib.sessions.backends.cache in your settings.py.

so, in your settings.py like this :

...
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
...

by the way, as in the documentation say :

‘..the simple cache is faster because it disregards persistence.’

you can cek in this link

0👍

If you have added/updated table in any models.py file, you might need to migrate the db before running the server.

Run below commands before running ‘python manage.py runserver’:

python manage.py migrate
python manage.py makemigrations 
👤SBT

0👍

That happens when you run the server without a database created or the session table inside of it (in case you recently add the admin app to your INSTALLED_APPS). In order to create the database or the table run this command.

python manage.py migrate

In older versions of django is this command

python manage.py syncdb

0👍

It prompted you to that error page because your Database wasn’t even created, which lead to the absence of the mandatory tables to access the admin page.

Run the following two commands :

python3 manage.py migrate

python3 manage.py makemigrations

Running the first command actually creates your database which holds the necessary starter tables. I had the same problem and this solved 100% for me.

Solution source : @satya ‘s answer

-1👍

Executing in the below order works fine:

First

 python manage.py migrate

Then

 python manage.py runserver.

Since we are applying all migrations before running the server.

Leave a comment