我收到了很多错误的信息:

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

作为Django项目的数据库引擎,从python-psycopg改为python-psycopg2。

代码保持不变,只是不知道这些错误来自哪里。


当前回答

你只需要跑

rollback;

在PostgreSQL中,就是这样!

其他回答

只需使用回滚

示例代码

try:
    cur.execute("CREATE TABLE IF NOT EXISTS test2 (id serial, qa text);")
except:
    cur.execute("rollback")
    cur.execute("CREATE TABLE IF NOT EXISTS test2 (id serial, qa text);")

我也遇到了类似的问题。解决方案是迁移db (manage.py syncdb或manage.py schemmigration——auto <表名>如果您使用south)。

你只需要跑

rollback;

在PostgreSQL中,就是这样!

在Flask shell中,我所需要做的就是一个session.rollback()来解决这个问题。

如果你在交互式shell中得到这个,需要快速修复,请这样做:

from django.db import connection
connection._rollback()

最初见于这个答案