本文介绍了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
发布评论