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

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


This is what postgres does when a query produces an error and you try to run another query without first rolling back the transaction. (You might think of it as a safety feature, to keep you from corrupting your data.)

To fix this, you'll want to figure out where in the code that bad query is being executed. It might be helpful to use the log_statement and log_min_error_statement options in your postgresql server.


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

from django.db import transactiontransaction.rollback()

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

from django.db import transaction, DatabaseErrortry:    a.save()except DatabaseError:    transaction.rollback()

Refer : Django documentation


In Flask you just need to write:

curs = conn.cursor()curs.execute("ROLLBACK")conn.commit()

P.S. Documentation goes here https://www.postgresql.org/docs/9.4/static/sql-rollback.html