In my recent experience, the mentioned errors happen this way:
# transaction on the DB is now bad
# transaction on db is still very bad
# 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.
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