1

这个问题已经被问了很多,但仍然,似乎没有任何工作。我的应用程序在测试中运行完美,但在 heroku 上运行时,我收到错误 500,说“我们很抱歉,但出了点问题”。我检查了服务器的日志文件,我的错误似乎在某处:

2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]: Started GET "/" for 117.192.23.223 at 2012-10-21 15:29:40 +0000
2012-10-21T15:29:40+00:00 app[web.1]: cache: [GET /] miss
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 heroku[router]: GET whispering-coast-7415.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=5ms status=301 bytes=115
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]: Started GET "/movies" for 117.192.23.223 at 2012-10-21 15:29:40 +0000
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]:   Processing by MoviesController#index as HTML
2012-10-21T15:29:40+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms
2012-10-21T15:29:40+00:00 heroku[router]: GET whispering-coast-7415.herokuapp.com/movies dyno=web.1 queue=0 wait=0ms service=17ms status=500 bytes=728
2012-10-21T15:29:40+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR:  column "movies.id" must appear in the GROUP BY clause or be used in an aggregate function
2012-10-21T15:29:40+00:00 app[web.1]: LINE 1: SELECT "movies".* FROM "movies"  GROUP BY rating
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]:                ^
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]: cache: [GET /movies] miss
2012-10-21T15:29:40+00:00 app[web.1]: : SELECT "movies".* FROM "mo
vies"  GROUP BY rating):
2012-10-21T15:29:40+00:00 app[web.1]:   app/controllers/movies_controller.rb:11:in `index'
2012-10-21T15:29:40+00:00 app[web.1]:   app/models/movie.rb:4:in `get_ratings'
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:41+00:00 heroku[router]: GET whispering-coast-7415.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=8ms status=200 bytes=0
2012-10-21T15:29:41+00:00 app[web.1]: cache: [GET /favicon.ico] stale, invalid, store

4

1 回答 1

0

PostgreSQL(在 Heroku 上)要求您对 SELECT 列表中的所有列进行 GROUP BY ,因此在这种情况下,而不是:

SELECT "movies".* FROM "movies"  GROUP BY rating

您可能想要执行以下操作:

SELECT rating FROM "movies" GROUP BY rating

或在 Rails 中:

Movie.select(:rating).group(:rating)
于 2013-02-08T04:26:28.600 回答