[Django]-Django: no such table: django_session

57๐Ÿ‘

โœ…

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 ๐Ÿ™‚

75๐Ÿ‘

After made any changes in code, run the following commands

manage.py makemigrations
manage.py migrate

it worked for me.

๐Ÿ‘คCMY

33๐Ÿ‘

run this in command shell:

python manage.py migrate

This fixed for me.

๐Ÿ‘คCodeBlooded

15๐Ÿ‘

In case it helps anyone else: the problem for me was that I didnโ€™t have the django.contrib.sessions app uncommented in my INSTALLED_APPS. Uncommenting it, and rerunning a syncdb did the trick.

๐Ÿ‘คGervase Markham

15๐Ÿ‘

In my case the problem was that I forgot to run manage.py syncdb after I made some changes. When I did that the problem was solved.

9๐Ÿ‘

When I run โ€œmanage.py runserverโ€. If I run when I my current path is not in project dir.(such as python /somefolder/somefolder2/currentprj/manage.py runserver) Iโ€™ll got the problem like you. solve by cd to project directory before run command.

6๐Ÿ‘

One other possible cause can come from using:

./manage.py testserver

And then visiting the admin interface. This wonโ€™t work because testserver creates a completely separate database in memory. If you want to visit the admin interface you need to use runserver.

๐Ÿ‘คaychedee

5๐Ÿ‘

This can happen if there are pending session migrations.

You have 17 unapplied migration(s). Your project may not work properly
until you apply the migrations for app(s): admin, auth, contenttypes,
sessions.

You can use the following command to run the migrations:

python manage.py migrate

This will fix the issue.

4๐Ÿ‘

It happens may be beacause of undone migrations

โ€ข Executes following commands:

python manage.py showmigrations

python manage.py migrate --fake your_app_name zero

python manage.py showmigrations

โ€ข IF you are running on local machine, then remove file named 0001.init.py from migrations folder in your app

โ€ข Executes following commands:

python manage.py makemigrations

python manage.py migrate

โ€ข then run django server:

python manage.py runserver

๐Ÿ‘คngandhi_369

3๐Ÿ‘

had the same issue, my resolution was to simply add โ€˜django.contrib.commentsโ€™ to INSTALLED_APPS and run ./manage.py syncdb again.

๐Ÿ‘คMidge

3๐Ÿ‘

I had similar problem for admin management. After several checks, run โ€œpython manage.py migrateโ€ without assign APPโ€™s name (get โ€œApply all migrations: โ€ฆ..), then runserver and up on the web. It worked. I hope this could help.

๐Ÿ‘คjayson888

3๐Ÿ‘

You have unapplied migrations. your app may not work properly until they are applied.
Run โ€˜python manage.py migrateโ€™ to apply them.
python manage.py migrate This one worked for me.

๐Ÿ‘คSanjay

3๐Ÿ‘

Maybe you have some unmigrated files.

Run
Python manage.py makemigrations appname
python manage.py migrate appname
python manage.py runserver

But if the error still continue
The run python manage.py migrate
The run server

๐Ÿ‘คTech Voltage

3๐Ÿ‘

In my case I only focused on different project and did not migrate the main application.

so first:

manage.py makemigrations
manage.py migrate

and then to the projectโ€™s:

manage.py makemigrations <my other project name>
manage.py migrate <my other project name>

๐Ÿ‘คadir abargil

2๐Ÿ‘

create a schema and add its name under NAME in โ€˜databasesโ€™
run manage.py syncdb

๐Ÿ‘คdevesh

2๐Ÿ‘

Maybe it is not getting the path of db. Just add this to your settings.py:

import os
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))

#modify your db NAME as below:
'NAME': os.path.join(PROJECT_PATH,'mysite.sqlite3'),
๐Ÿ‘คeswar

2๐Ÿ‘

I had made some changes in Model which was not migrated to db properly. Using the command

manage.py makemigrations

fixed my problem. I hope this will help someone.

2๐Ÿ‘

syncdb is obsolete try python manage.py makemigrations and python manage.py migrate solved the problem ,and donot forget to add the app name is the installed app in settings.py

๐Ÿ‘คPranoy Sarkar

2๐Ÿ‘

I had the same problem so I ran

heroku run ls

and found that the db.sqlite3 file was missing from the server.
In my case, it was because I exempted it by adding it in .gitignore file.

๐Ÿ‘คSteev James

1๐Ÿ‘

Had this problem too. Restarting postgres and apache2 did it for me. Makes me wonder if there was some kind of sqlite process left over which wasnโ€™t removed until you fiddled with the files or something.

๐Ÿ‘คWill S

1๐Ÿ‘

I had this issue in a different scenario. I am new to Django and cloned a repository from github to practice on it. The file db.sqlite3 was also copied. But there was no django_session in it. When I did

./manage.py showmigrations

.. I found out that there were some migrations. But the tables were missing in sqlite, as I never ran migrate. My issue was resolved when I ran the migrate command. Hope this helps django newbies like me.

./manage.py migrate
๐Ÿ‘คVikas

1๐Ÿ‘

Add 'django.contrib.sessions', line in INSTALLED_APPS

Run below commands from django shell

python manage.py makemigrations  #check for changes
python manage.py migrate #apply changes in DbSQLite
python manage.py syncdb #sync with database

django_session will appear in database with (session_key, session_data , expire_date)

๐Ÿ‘คRoshan Bagdiya

1๐Ÿ‘

In my case, I had to erase the โ€˜sessionsโ€™ entry in the django_migrations table and run makemigrations and migrate afterwards. That created the django_session table.

1๐Ÿ‘

For me, it was that I updated settings.py, ran the migrations, but the systemd process was still using SQLite because I did not reload it. Doing systemctl restart service_name solved the problem.

๐Ÿ‘คPavel Vergeev

1๐Ÿ‘

And it may be a case you are getting this error because you forget to run query python manage.py migrate before creating super user

๐Ÿ‘คNikhil Bhardwaj

1๐Ÿ‘

If you are tired of using makemigrations and migrate but the error is same no such table django_session. Then just have a look to you code somewhere or the other you using session or calling it. Just comment the code where you are using session and then run the command makemigrations and migrate respectively. It 100% solve your issue.The cause of this error is that you deleted your migrations folder and database file that is the reason you are getting this error.Feel free to ask if problem is not solve

๐Ÿ‘คArun

1๐Ÿ‘

This worked for me.

From https://docs.djangoproject.com/en/2.2/topics/http/sessions/

Using database-backed sessions โ€“

If you want to use a database-backed session, you need to add โ€˜django.contrib.sessionsโ€™ to your INSTALLED_APPS setting.

Once you have configured your installation, run manage.py migrate to install the single database table that stores session data.

1๐Ÿ‘

Please try the following command when you change on your code

manage.py makemigrations
manage.py migrate
๐Ÿ‘คVaishali Shinde

1๐Ÿ‘

Simply run this commands

python manage.py makemigrations
python manage.py migrate
python manage.py runserver
๐Ÿ‘คMD SHAYON

1๐Ÿ‘

itโ€™s simple just run the following command

python ./manage.py migrate
python ./manage.py makemigrations AppName
๐Ÿ‘คThe.lYNCAN

1๐Ÿ‘

I found thatโ€™s it all about migratinge.

python manage.py makemigrations APPNAME

As the answer ticked brakes when changed to a different virtual host such as windows to linux and vice versa

๐Ÿ‘คMarcus Rose

0๐Ÿ‘

run the command in the terminal or cmd prompt

python manage.py runserver

and then

python manage.py createsuperuser 

then create superuser by setting username and password then you will be able to see the admin login page.

๐Ÿ‘คSameer Vaghela

0๐Ÿ‘

In my case, the problem happened right after installing "Debug-toolbar" with empty models.py (with no classes), so the exact solution to my case is running those codes:

python manage.py makemigrations
python manage.py migrate
python manage.py runserver

that is what I want to demonstrate for this annoying problem.

๐Ÿ‘คazizmech

0๐Ÿ‘

Django documentation says "Once you have configured your installation, run manage.py migrate to install the single database table that stores session data."

One possibility that i have come across is if the migration is ran for app first time before running migrations for the new project so just run migrations for the project

python manage.py makemigrations
python manage.py migrate

later you can run if needed

python manage.py makemigrations APPNAME
python manage.py migrate APPNAME
๐Ÿ‘คArjun Raghav A

0๐Ÿ‘

  1. I deleted the existing migration files from folder with name 0001_initial.py
  • Note: Donโ€™t delete any database/migrations file if you are working on live project.
  1. Then deleted the db.sqlite3 database
    and ran the below 4 commands and it worked.

     python manage.py makemigrations
     python manage.py migrate
     python manage.py createsuperuser
     python manage.py runserver
    
๐Ÿ‘คpintz

-1๐Ÿ‘

Run this command in cmd :

Python ./manage.py migrate --all

It should come on your db

Leave a comment