Django + Postgres:“当前事务被中止,忽略直到事务块结束的命令” [英] Django+Postgres: "current transaction is aborted, commands ignored until end of transaction block"

查看:97
本文介绍了Django + Postgres:“当前事务被中止,忽略直到事务块结束的命令”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在Django / Postgres网站上工作。有时我在 manage.py shell 中工作,并且意外地做了一些导致错误的DB操作。那么我根本无法执行任何数据库操作,因为对于我尝试执行的任何数据库操作,我收到错误:

 当前事务中止,忽略事务处理结束前的命令

我的目前的解决方法是重新启动shell,但是我应该找到一种方法来解决这个问题而不放弃我的shell会话。



(我已经阅读这个这个,但是它们没有提供关于从shell中做什么的可操作的说明

解决方案

您可以尝试这样:

  from django.db import connection 
connection._rollback()

更详细的讨论此问题可以在这里找到


I've started working on a Django/Postgres site. Sometimes I work in manage.py shell, and accidentally do some DB action that results in an error. Then I am unable to do any database action at all, because for any database action I try to do, I get the error:

current transaction is aborted, commands ignored until end of transaction block

My current workaround is to restart the shell, but I should find a way to fix this without abandoning my shell session.

(I've read this and this, but they don't give actionable instructions on what to do from the shell.)

解决方案

You can try this:

from django.db import connection
connection._rollback()

The more detailed discussion of This issue can be found here

这篇关于Django + Postgres:“当前事务被中止,忽略直到事务块结束的命令”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆