3

I am pretty sure that database has been created and I have executed python manage.py syncdb properly but still i encounter this error when trying to access http://127.0.0.1:8000/admin/. Here are some details.

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'blog',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Exception Type: DatabaseError at /admin/
Exception Value: no such table: django_session
3
  • 1
    Can you see the table in your db? What engine are you using?
    – sberry
    Oct 21, 2011 at 3:21
  • I'd bet that you haven't run syncdb - does running that fix the problem? Oct 21, 2011 at 5:52
  • Ah.. My usual mistakes. i skipped the part where it read use forward slashes in path EVEN ON WINDOWS. Oct 21, 2011 at 7:01

8 Answers 8

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
0
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', '[email protected]'),)
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
  • 1
    peters approach worked for me, although using linux and having my db located in the same dir as manage.py i changed the second line to ROOT = dirname(abspath(__file__ + '/..')) + '/'
    – antiplex
    Mar 25, 2013 at 19:27
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 
1
  • I think that generating migrations after the migrate command would make you run again the migrate
    – Jorge Luis
    Mar 17, 2021 at 4:22
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.

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.