关于Heroku(Postgres)的Where子句中断但在本地工作正常(MySQL)

时间:2012-04-09 12:08:16

标签: mysql postgresql heroku

我有以下代码行在本地工作正常,但在推送到Production(Heroku)时中断:

def self.find_unresolved_with_approved_client
  self.joins(:client).where('clients.approved = true AND wish.status <> "Resolved"')
end

我的heroku日志中的错误如下:

2012-04-09T11:49:14+00:00 app[web.1]: ActionView::Template::Error (PGError: ERROR:  column "Resolved" does not exist
2012-04-09T11:49:14+00:00 app[web.1]:     16:       %th{ :class => :span10 } Subject
2012-04-09T11:49:14+00:00 app[web.1]:     17:       %th{ :class => :span4 } Status
2012-04-09T11:49:14+00:00 app[web.1]: LINE 1: ...ERE (clients.approved = true AND wishes.status != "Resolved"...
2012-04-09T11:49:14+00:00 app[web.1]: : SELECT  "wishes".* FROM "wishes" INNER JOIN "clients" ON "clients"."id" = "wishes"."client_id" WHERE (clients.approved = true AND wishes.status != "Resolved") ORDER BY wishes.id LIMIT 25 OFFSET 0):

为什么在本地进行文字比较时尝试对Production进行列比较?

1 个答案:

答案 0 :(得分:2)

您应该将查询更改为.where('clients.approved =?AND wish.status!=?',true,'已解决') 这使得适配器为您构建查询,这将解决不同数据库具有略微不同的查询语法的问题