ActiveRecord::StatementInvalid: PG InFailedSqlTransaction 活动记录:语句无效,PG事务失败。

84
我正在尝试创建一个ActiveRecord对象,但在创建时出现了这个错误。
(0.1ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR:  current transaction is       aborted, commands ignored until end of transaction block

关于这个问题,有什么想法吗?


你是否在使用列类型为 json 的 PSQL?将其更新至 PSQL 9.4 并使用 jsonb。问题解决! - germs12
这是我们遇到的主要问题。请参考以下链接:https://www.postgresql.org/docs/9.1/static/transaction-iso.html - untwal
12个回答

0
在终端上运行这两个命令:
$ rm /opt/homebrew/var/postgres/postmaster.pid  # (Here maybe have different path)
$ brew services restart postgresql

从我的角度来看,这是可行的。


0

我遇到了这个问题。 后来发现是我的查询语句有问题。 也就是在联表查询时没有指定表列。

class Holiday < ApplicationRecord
     belongs_to :company
end

class Company < ApplicationRecord
    has_many :timeoffs
end

在假期模型中,我进行查询。
company.timeoffs.where("(start_date <= ? and end_date >= ?) and id != ?", begin_date, begin_date, 1)

错误发生是因为我没有指定哪个表的id。在我将代码更改为以下内容后,它对我起作用了。
company.timeoffs.where("(start_date <= ? and end_date >= ?) and time_offs.id != ?", begin_date, begin_date, 1)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接