Solution :
In my recent experience, the mentioned errors happen this way:
try:
The_code_that_executes_bad_query()
# transaction on the DB is now bad
except:
pass
# transaction on db is still very bad
The_code_that_executes_working_query()
# raises the transaction error
There is nothing wrong with my second query, but since my real error was caught, so my second query is the one that will raise my very less informative error.
This only happens if my except
clause catches the IntegrityError
or any other exception from the low level database exception, If you can catch something like DoesNotExist
then this error will not show up, as DoesNotExist
does not corrupt my transaction.
So the lesson here is don't do the try/except/pass.
OR
If you get above mentioned error while in the interactive shell and you need the quick fix, then simply do this:
from django.db import connection
connection._rollback()