![](/img/trans.png)
[英]ActiveRecord::StatementInvalid: PG InFailedSqlTransaction
[英]Rails Rspec - ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction:
我有这个控制器方法
def dashboard
method1
method2
method3
..
end
在development
环境中一切正常......但在test
环境中,我在前几种方法后收到此错误。
我使用binding.pry
在我曾经出错的行上方进行了检查,
我无法运行任何查询, eg: Account.first
但相同的Account.first
在dev
环境中工作
在test
环境中运行时出错:
ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
: SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT 1
from /home/qwinix/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:596:in `async_exec'
请注意以下事项
method1
添加了一些代码,它在两种环境中都可以正常执行。 我收到后,这些错误method3
,我还没有触及。PS:我做了谷歌和搜索stackoverflow问题,没有帮助
编辑:当我提出的method1
结束,我没有得到任何错误,请解释我这种行为。
您是否尝试重置测试数据库?
bundle exec rails db:drop RAILS_ENV=test
bundle exec rails db:create RAILS_ENV=test
bundle exec rails db:schema:load RAILS_ENV=test
或者对于低于 5 的 Rails 版本
bundle exec rake db:drop RAILS_ENV=test
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test
或更短:
bundle exec rake db:reset RAILS_ENV=test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.