Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I got a lot of errors with the message :

"DatabaseError: current transaction is aborted, commands ignored until end of transaction block"

after changed from python-psycopg to python-psycopg2 as Django project's database engine.

The code remains the same, just don't know where those errors are from.

1 Answer

0 votes
by (106k points)

To get rid of the error, roll back the last (erroneous) transaction after you've fixed your code:

from django.db import transaction 

transaction.rollback()

You can use try-except to prevent the error from occurring:

from django.db import transaction, DatabaseError 

try: 

a.save() 

except DatabaseError: 

transaction.rollback()

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...