Rails控制台出现current transaction is aborted错误的解决

来源:互联网 发布:中博软件学院 编辑:程序博客网 时间:2024/05/20 12:25

今日在Rails console中做出一次错误查询之后,出现如上错误:

Risk.find_by(some_key:1)

注意Risk类没有some_key这个属性,果然出错了:

PG::UndefinedColumn: ERROR:  column risks.some_key does not exist

不但如此,之后的任何合法操作全部出错:

PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block

由于我是用的是postgresql,如果发生这种情况需要重新commit或者rollback:

ActiveRecord::Base.connection.execute 'ROLLBACK'

之后查询都正常了.

0 0