消息有很多错误:"DatabaseError: current transaction is aborted, commands ignored until end of transaction block"从python-psycopg更改为python-psycopg2作为Django项目的数据库引擎。代码保持不变,只是不知道这些错误来自何处。
3 回答

哆啦的时光机
TA贡献1779条经验 获得超6个赞
当查询产生错误并且您尝试运行另一个查询而不先回滚事务时,这就是postgres所做的。(您可能会认为这是一项安全功能,可以防止您破坏数据。)
要解决此问题,您将需要弄清楚错误查询在代码中的何处执行。在您的PostgreSQL服务器中使用log_statement和log_min_error_statement选项可能会有所帮助。

慕容3067478
TA贡献1773条经验 获得超3个赞
要消除错误,请在修复代码后回滚上一个(错误的)事务:
from django.db import transaction
transaction.rollback()
您可以使用try-except来防止发生错误:
from django.db import transaction, DatabaseError
try:
a.save()
except DatabaseError:
transaction.rollback()
添加回答
举报
0/150
提交
取消