ActiveRecord :: StatementInvalid:PG InFailedSqlTransaction

编程入门 行业动态 更新时间:2024-10-28 11:23:51
本文介绍了ActiveRecord :: StatementInvalid:PG InFailedSqlTransaction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建ActiveRecord对象。但是在创建它时遇到此错误。

I am trying to create an ActiveRecord Object.But I'm getting this error while creating it.

(0.1ms) ROLLBACK ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block

有关此问题的任何想法。

Any ideas folks regarding the issue.

推荐答案

没有其他答案可以解决 问题的根本原因 。

None of the other answers fix the root cause of the issue.

问题在于,当Postgres引发异常时,它会毒害同一交易的未来交易

The problem is that when Postgres raises an exception, it poisons future transactions on the same connection.

解决方法是回滚有问题的交易:

The fix is to rollback the offending transaction:

begin ActiveRecord...do something... rescue Exception => e puts "SQL error in #{ __method__ }" ActiveRecord::Base.connection.execute 'ROLLBACK' raise e end

请参见参考。

更多推荐

ActiveRecord :: StatementInvalid:PG InFailedSqlTransaction

本文发布于:2023-10-16 15:47:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498018.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:StatementInvalid   ActiveRecord   InFailedSqlTransaction   PG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!