![](/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.