Reputation: 1021
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.
Upvotes: 74
Views: 149101
Reputation: 301
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
Upvotes: 0
Reputation: 5745
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>
Upvotes: 3
Reputation: 13
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
Upvotes: 0
Reputation: 23
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.
Upvotes: 0
Reputation: 37
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
Upvotes: 3
Reputation: 41
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'),
Upvotes: 2
Reputation: 61
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
Upvotes: 1
Reputation: 159
it's simple just run the following command
python ./manage.py migrate
python ./manage.py makemigrations AppName
Upvotes: 1
Reputation: 8063
Simply run this commands
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
Upvotes: 1
Reputation: 91
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.
Upvotes: 0
Reputation: 397
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
Upvotes: 4
Reputation: 552
Please try the following command when you change on your code
manage.py makemigrations
manage.py migrate
Upvotes: 1
Reputation: 3168
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.
Upvotes: 6
Reputation: 809
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.
Upvotes: 1
Reputation: 4204
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
Upvotes: 1
Reputation: 582
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
Upvotes: 1
Reputation: 2654
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.
Upvotes: 2
Reputation: 3380
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.
Upvotes: 1
Reputation: 408
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.
Upvotes: 1
Reputation: 2178
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)
Upvotes: 1
Reputation: 2028
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
Upvotes: 1
Reputation: 533
run this in command shell:
python manage.py migrate
This fixed for me.
Upvotes: 36
Reputation: 688
Run this command in cmd :
Python ./manage.py migrate --all
It should come on your db
Upvotes: -1
Reputation: 2233
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
Upvotes: 2
Reputation: 31
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.
Upvotes: 3
Reputation: 869
After made any changes in code, run the following commands
manage.py makemigrations
manage.py migrate
it worked for me.
Upvotes: 82
Reputation: 31
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.
Upvotes: 3
Reputation: 868
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.
Upvotes: 2
Reputation: 755
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.
Upvotes: 1
Reputation: 21
create a schema and add its name under NAME in 'databases' run manage.py syncdb
Upvotes: 2