我有一个Rails应用程序,在开发中(SQLite)运行良好,但是当我通过使用PostgreSQL的Heroku部署它时,会出现许多错误。
返回的错误消息:
ActionView::Template::Error (PGError: ERROR:
column "practices.id" must appear in the GROUP BY clause or be used in an aggregate function:
SELECT "practices".*
FROM "practices" WHERE ("practices".activity_id = 1)
AND ("practices"."created_at" BETWEEN '2011-01-01' AND '2011-01-31')
GROUP BY DATE(created_at) ORDER BY created_at DESC):
当我调用以下内容时,会抛出这个异常:
def month_days_not_practiced(date = Date.today)
p = practices.where(:created_at => date.at_beginning_of_month..date.at_end_of_month).group("DATE(created_at)").to_a.count
days_in_month(date.year, date.month) - p
end
我希望代码能保持干净,这样它就可以在开发和生产数据库上正常运行......有人能解释一下吗?
我尝试过以下方法:
def month_days_not_practiced(date = Date.today)
p = practices.where(:created_at => date.at_beginning_of_month..date.at_end_of_month).group("practices.id, DATE(created_at)").to_a.count
days_in_month(date.year, date.month) - p
end
无济于事...
谢谢。
.all
。我确定我在这里漏掉了什么,但迄今为止我还没有找到答案。 - wuliwong