Django: no such table: django_session

I have found several topics with this title, but none of their solutions worked for me. I have two Django sites running on my server, both through Apache using different virtualhosts on two ports fed by my Nginx frontend (using for static files). One site uses MySql and runs just fine. The other uses Sqlite3 and gets the error in the title.

I downloaded a copy of sqlite.exe and looked at the mysite.sqlite3 (SQLite database in this directory) file and there is indeed a django_session table with valid data in it. I have the sqlite.exe in my system32 as well as the site-packages folder in my Python path.

Here is a section of my settings.py file:

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'mysite.sqlite3',         # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

I did use the python manage.py syncdb with no errors and just a "No Fixtures" comment.

Does anyone have any ideas what else might be going on here? I'm considering just transferring everything over to my old pal MySql and just ignoring Sqlite, as really it's always given me some kind of trouble. I was only using it for the benefit of knowing it anyway. I have no overwhelming reason why I should use it. But again, just for my edification does anyone know what this problem is? I don't like to give up.


Solution 1:

It could be that the server uses a different working directory than the manage.py command. Since you provide a relative path to the sqlite database, it is created in the working directory. Try it with an absolute path, e.g.:

'NAME': '/tmp/mysite.sqlite3',

Remember that you have to either run ./manage.py syncdb again or copy your current database with the existing tables to /tmp.

If it resolves the error message, you can look for a better place than /tmp :-)

Solution 2:

After made any changes in code, run the following commands

manage.py makemigrations
manage.py migrate

it worked for me.

Solution 3:

run this in command shell:

python manage.py migrate

This fixed for me.