I used to know how to do this, but I forgot. Sometimes, while using the Django shell, you make a mistake and cause the transaction to become aborted. After that, any further queries you do will result in DatabaseError: current transaction is aborted, commands ignored until end of transaction block. However, I think there is a way to rollback the transaction when this happens manually so you don't have to restart your session. Can anyone tell me what it is?
This bug report (https://code.djangoproject.com/ticket/10813) makes reference to the technique but doesn't explain it. Running django.db.transaction.rollback results in "TransactionManagementError: This code isn't under transaction management".
This happens to me all the time when using Postgres, and it's really irritating.
You want:
from django.db import transaction
transaction.rollback()
Most of the time this is fine (and in my experience, it's safe to ignore the TransactionManagementError
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With