ActiveRecord::StatementInvalid: PG InFailedSqlTransaction

后端 未结 10 2072
礼貌的吻别
礼貌的吻别 2020-12-13 01:33

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

(0.1ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::InFailedSql         


        
10条回答
  •  离开以前
    2020-12-13 02:18

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

    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
    

    See reference.

提交回复
热议问题