Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL, Rails + Heroku, Column must appear in “group by” error #1

Open
washingtoneg opened this issue Apr 4, 2012 · 6 comments

Comments

@washingtoneg
Copy link

I am trying to deploy my first rails app to Heroku and seem to be having a problem. After I git push heroku master, and heroku rake db:migrate I get an error in my app that says "We're sorry, but something went wrong." After checking my Heroku log I see the following:

Completed 500 Internal Server Error in 11ms ActionView::Template::Error (PG::Error: ERROR: column "messages.id" must appear in the GROUP BY clause or be used in an aggregate function : SELECT  "messages".* FROM "messages"  WHERE "messages"."user_id" = 1 AND "messages"."deleted" = 'f' AND "messages"."copies" = 'f' GROUP BY subject_id LIMIT 10 OFFSET 0): 

 15: <!-- this will render the messages -->
 16: <%- 
 17:        x = 0 
 18:        @messages.reverse_each do |message|
 19:            convTree = message.root.subtree
 20:            
 21:            flag = convTree.where(:copies => false).empty

 app/views/messages/_messages.html.erb:18:in block in_app_views_messages__messages_html_erb_3345815185511210855_36008620
 app/views/messages/_messages.html.erb:1:in _app_views_messages__messages_html_erb_3345815185511210855_36008620
 app/views/messages/index.html.erb:8:in _app_views_messages_index_html_erb___44790182404171_40771920`
 cache: [GET /messages] miss'

From searching Google I have found a related question on Stackoverflow and this article. It seems that this issue lies in the fact that PostgreSQL is more SQL compliant than MySQL and the "solution to fixing this is to use :select and to select each field that you wish to decorate the resulting object with and group by them." However, I'm not exactly sure how to augment the code in my messages partial to make PostgreSQL happy.

Please note that I'm using the messages partial as generated.

Thanks for the help!

@myKingEdem
Copy link

Were you able to send messages to multiple recipients?

@washingtoneg
Copy link
Author

On the development side, yes, but everything breaks when I try it out in production on Heroku.

@myKingEdem
Copy link

Did you change anything in particular in development mode? The create action in particular, line 40 in the Messages Controller...I get this message!

Couldn't find all Users with IDs (rexpraseo_1, rexpraseo_2, rexpraseo_3) (found 0 results, but was looking for 3)
app/controllers/messages_controller.rb:40:in `create'

Framework Trace
activerecord (3.2.3) lib/active_record/relation/finder_methods.rb:369:in find_some' activerecord (3.2.3) lib/active_record/relation/finder_methods.rb:314:infind_with_ids'
activerecord (3.2.3) lib/active_record/relation/finder_methods.rb:107:in find' activerecord (3.2.3) lib/active_record/querying.rb:5:infind'

@washingtoneg
Copy link
Author

I didn't change anything in the messages generator. The only thing I can see being the root cause of this issue is that I used sqlite3 (I was mistaken when I previously stated MySQL) in development and PostgreSQL in production because it is required by Heroku.

Are you also having problems?

@myKingEdem
Copy link

I've only tried it in development...single recipients are working fine...I'm user rails 3.2.3, with sqlite3 in dev! I want to fix this before I try it on heroku!

@washingtoneg
Copy link
Author

You can try deploying to Heroku, but I'm pretty sure you'll run into the same issue.

Unfortunately, there hasn't been an answer to this issue. You may want to try another messaging gem/generator until this gets resolved (I don't have one to recommend at the moment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants