2

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.

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
Hrishikesh D Kakkad
  • 171
  • 1
  • 1
  • 12
  • you can find the solution here https://stackoverflow.com/questions/53637182/django-no-such-table-main-auth-user-old/ – Joshua Agar Feb 11 '20 at 14:05

10 Answers10

5

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.

Yogesh Nikam Patil
  • 1,192
  • 13
  • 18
4

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.

3

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):

  1. close any terminal windows in PyCharm or other 'runserver' instances
  2. delete db.sqlite3

Then upgrade Django like this in a terminal window pip install --upgrade django==2.1.5 Once it's done, you rebuild.

  1. open a terminal window in PyCharm, type: python manage.py makemigrations and hit enter. It should say no changes detected.
  2. Then type: python manage.py migrate, it'll rebuild db.sqlite3
  3. Then: python manage.py runserver and let that run.
  4. Open a new terminal, type python manage.py createsuperuser and follow prompts.
  5. Open http://127.0.0.1:8000/admin , enter the details you just created, and you're working.
tk20blue
  • 45
  • 3
2

It's a compatibility issue between latest SQLite and Django. See here: Django - No such table: main.auth_user__old

Bernhard
  • 661
  • 4
  • 6
  • So how do I downgrade Sqlite to 2.5.1, while it's running? – Hrishikesh D Kakkad Jan 07 '19 at 08:44
  • If you installed it manually, you could just install an older version. Due to your question, I assume you didn't and so you are using a system-provided SQlite. You shouldn't try to downgrade it, it may break your system. Try to use Django master branch from github (https://github.com/django/django) or use the described workaround (https://stackoverflow.com/a/53848684/140450). – Bernhard Jan 07 '19 at 09:28
1

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:

  1. exit the IDE you are using
  2. delete db.sqlite from the folder in your computer not inside the IDE
  3. open your IDE and upgrade your django version using this command pip install --upgrade django==2.1.5
  4. run this command python manage.py makemigrations
  5. then run this command python manage.py migrate
  6. this will help you Enchallah
0

When I used the python shell to add to database instead of the UI, error did not show anymore

$ python manage.py shell

In the python shell

from AppName.models import Product
Product.objects.create(title='Newer', price=239.99, summary='awesome')
d2a2d
  • 1,176
  • 10
  • 12
0

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!

  • A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. – Usama Abdulrehman Jun 17 '20 at 00:34
  • SQLite 3.26 repoints foreign key constraints on table renames even when foreign_keys pragma is off which breaks every operation that requires a table rebuild to simulate unsupported ALTER TABLE statements. Fortunately the newly introduced legacy_alter_table pragma allows one to disable this behavior and restore the previous schema editor assumptions. from GitHub django files – Koome Mwiti Jun 17 '20 at 01:47
  • @UsamaAbdulrehman That GitHub link leads to the exact page, if you copy the link address, it generates a unique session ID every time an thus cannot copy but anyone can access and download the pdf document in that repo since I have made it a public repo. Thanks! – Koome Mwiti Jun 17 '20 at 01:50
0

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!

umairnsr87
  • 91
  • 7
0

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),
)"
-1

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.

Sushant
  • 132
  • 2
  • 12