回答

收藏

ActiveRecord :: StatementInvalid。PG错误

技术问答 技术问答 230 人阅读 | 0 人回复 | 2023-09-14

我正在尝试从Project使用的模型中找到一个项目,Project.find(id)但这给了我ActiveRecord::StatementInvalid错误6 A- F: c7 Y) P
全程跟踪/ {+ U. u/ B; C# S; q/ t
PG::Error: ERROR: prepared statement "a1" already exists : SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind in ('v','r') AND c.relname = $1 AND n.nspname = ANY (current_schemas(false))
+ n% B; g% T) `# i/ b1 j/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1180:in `prepare'
4 G5 A7 N! r( _2 \$ \/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1180:in `prepare_statement'
) y0 Z* C& F- v* n; S/ N/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1144:in `exec_cache'2 l) h& x& q  q; l$ h4 a
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-     3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `block in exec_query'1 g, v7 N6 n; K
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
- u! e0 S# g1 b- U/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'; M5 C( r# W6 [/ x) k$ O( g- {& k
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'$ [9 i& a$ |  `: t9 y5 ]0 L
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:662:in `exec_query'" O! Z5 @, p4 J" ^
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:797:in `table_exists?'
7 ^4 x' l, l) T. |! S4 b2 u/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:30:in `table_exists?'6 Q7 P* E* w' J" G& ^
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:223:in `table_exists?'
; {. n! Q4 m$ P/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/attribute_methods/primary_key.rb:75:in `get_primary_key'5 I+ C$ f$ S* D1 g" h8 A" D  N3 x: A8 D
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/attribute_methods/primary_key.rb:60:in `reset_primary_key'
" Z9 ^# ~% L! i' R8 j/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/attribute_methods/primary_key.rb:49:in `primary_key'
  Z! m0 b8 F0 ~- n# U% q, W/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:230:in `block in columns'
. X  O6 G  B) [- R/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `map'
, i( U2 b0 a# k6 R/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns'3 y3 g: a4 y, |* ?# f- S0 S
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:237:in `columns_hash'3 g( _6 V* K. q$ d3 ], y
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/delegation.rb:7:in `columns_hash'
6 V9 V; J9 _. V1 s/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:330:in `find_one'7 b5 g# x, T) ]* {) U
/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:311:in `find_with_ids'
8 k9 k% H  `9 o& Q/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:107:in `find'
$ E: }' y% ]8 c3 n7 T. L/home/deploy/.rvm/gems/ruby-1.9.2-p290@submit_contactpl/gems/activerecord-3.2.2/lib/active_record/querying.rb:5:in `find'
9 B( Z6 B* e4 S4 f- I. x/home/deploy/submit_contactpl/app/workers/php_worker.rb:5:in `perform') J" a4 }# k# n; N4 M7 i
的第5行php_worker是
7 X. f. e) r7 u! m7 y2 c project = Project.find(project_id)& R6 q2 S: K) B8 j& N3 L( l$ {
可能是什么问题?您可以在上面遮一下光吗?可能的解决方案是什么
1 e8 C9 O. a+ a' ~5 d               
7 t- |6 ^# O* {& i1 o解决方案:' ?! A" m8 l' C$ G) k
               
* T: {9 n4 `# q7 i! o( w; {- a. S9 N: Q3 Z2 P: D1 h7 Y& K" f

& s0 `# T; H% B7 j6 W$ F3 U2 ]                它所需要的只是
( Z8 A, v: L4 K0 Z1 k task "resque:setup" => :environment do3 r6 H% P) t: A% `( K. w) |& {
  #ENV['QUEUE'] = '*'0 G3 N+ \  U: c
  Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }  h( |9 a! n/ ^; m- W5 \; a+ Y
end
9 [; F# M( T. Q* ?8 Z% B9 S" s在您的resque.rake文件中
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则