Django main.app_table__old Error deleting item
I am facing this problem and I tried many solutions but no one works for me or it is not convinient of my case.
First I use Django==2.0 (can't change to version due to problems).
I have I model table named table
and my app is app
when developing it happend that I can't delete any element in that table (the other works fine). and I get this problem.
OperationalError at /fieldsdetails/25/delete/
no such table: main.app_table__old
I tried to delete all migrations history so the db.sqlite3 and run:
python manage.py makemigrations
python manage.py migrate
Then I tried to delete the table as
python manage.py dbshell
SELECT * FROM sqlite_master WHERE type='table';
then I found a table named app_table__old
and deleting it using this:
DROP TABLE app_table__old
.exit
but nothing works?
is there any solution I don't want to upgrade Django version or lose data.
I just discovered a tricky way to solve this without losing or changing or upgrading Django.
The problem happens when the sqlite lost some information in the data base.
To solve the problem follow those steps:
1- go to your models tables and search for other tables that have ForeignKey or any relation to the table
for example:
class table_Perimeter(models.Model):
Perimeter = models.ForeignKey( table, on_delete=models.CASCADE)
then when you define all tables that have relation with table. you need to fix the problem in the database itself db.sqlite3
.
install the SQLiteStudio browser from this site https://sqlitestudio.pl/
then go to table_Perimeter and double click on it. you will see something like this.
double click to re-configuration ForeignKey and you will see a red icon:
Here enter to configure it again
from this window select the foreig table and Foreig id and click apply
click to commit the changes
So everything will work perfectly just run your server :)