gpt4 book ai didi

postgresql - Rails 应用程序中的 Heroku PostgreSQL GROUP_BY 错误

转载 作者:行者123 更新时间:2023-11-29 11:31:30 25 4
gpt4 key购买 nike

我有一个在开发 (SQLite) 中运行良好的 Rails 应用程序,但是当我通过 Heroku 部署它时抛出了很多错误,我收集到它使用的是 PostgreSQL。

返回的错误信息:

        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

没用...

蒂亚。

最佳答案

Practice.group(Practice.col_list)



def self.col_list
Practice.column_names.collect {|c| "practices.#{c}"}.join(",")
end

关于postgresql - Rails 应用程序中的 Heroku PostgreSQL GROUP_BY 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4599010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com