Can someone give a detailed explanation on how to fix the ERROR: no such table: main.auth_user__old
It arises in my Django application when I am trying to add data to my registered models.
Can someone give a detailed explanation on how to fix the ERROR: no such table: main.auth_user__old
It arises in my Django application when I am trying to add data to my registered models.
I have solved this issue using below :
1) Delete the db.sqlit3
2) app's directory delete everything in pycache
3) manage.py makemigrations, manage.py migrate, manage.py createsuperuser and then manage.py runserver.
If you are using django==2.1 then maybe you getting this error. Just start your Django project again bu installing django==2.1.5 It will work.
This happened to me as a newbie, whilst following Mosh's intro course on the final project 3: Django. This is the fix, usually using Pycharm or it's equivalent (no need to change any of your code):
Then upgrade Django like this in a terminal window pip install --upgrade django==2.1.5
Once it's done, you rebuild.
python manage.py makemigrations
and hit enter. It should say no changes detected.python manage.py migrate
, it'll rebuild db.sqlite3python manage.py runserver
and let that run.python manage.py createsuperuser
and follow prompts.It's a compatibility issue between latest SQLite and Django. See here: Django - No such table: main.auth_user__old
first of all you don't have to change your code, the problem your django version I'm pretty sure that you're following mosh's tutorial or something like that, to fix this problem follow this steps:
When I used the python shell to add to database instead of the UI, error did not show anymore
$ python manage.py shell
from AppName.models import Product
Product.objects.create(title='Newer', price=239.99, summary='awesome')
There is no need to downgrade to any version of Django or SQL Lite but if you follow the steps I have outlined in this GitHub link https://github.com/komerela/django_troubleshooting you should be good to go... Once you click on the pdf document labeled "Sorting the SQLITE3 issue step by step solution.pdf"
You're welcome!
I know this issue is encountered a long time back I don't want anyone to stuck on it again:
Step1: The solution is to check the Django version if it is 2.1 then update it to 2.2 or later.
Step2: After updating to Django==2.2 or later Delete all old migrations from the migrations folder and delete the db.sqlite3 and then run makemigrations and migrations again. It will be resolved.
Good Luck!
I got this same error in Rust. I had a typo in the name of table2 (where table2 was referenced by a foreign key).
"create table if not exists table1 (
...
id_fk integer not null references table2(id),
)"
You probably haven't run the migrations. Until you run migrations, no tables are created. Hence the error. See https://docs.djangoproject.com/en/2.1/topics/migrations/#workflow
After you've registered your models, go to your git bash or powershell. Make sure you are in your project directory. Then run these commands :
python manage.py makemigrations
And then
python manage.py migrate
These commands will create tables for you and then you can add data to them.