【发布时间】:2012-04-21 09:40:17
【问题描述】:
我在 Heroku 上遇到了这个错误,但不是在本地(两者都使用 PostgreSQL)..
错误是:
ActiveRecord::StatementInvalid (PG::Error: ERROR: column "posts.content" must appear in the GROUP BY clause or be used in an aggregate function
我怀疑这与我的帖子模型中的这一行有关:
scope :with_tags, lambda { |tags| joins(:tags).group('posts.id').where(:tags => { :id => tags.map { |t| t.id } } ).having("COUNT(*) = ?", tags.length) }
为什么它只发生在 Heroku 上?我该如何解决?
【问题讨论】:
-
我不太确定这就是为什么我要添加评论但尝试将带有 post.id 的 post.content 放在 .group 括号中。
-
我添加了它,现在它在另一列上给出了该错误,必须有比手动添加帖子中的所有列更好的方法来解决这个问题..另外,我仍然想知道为什么它只发生在 Heroku而不是在本地 PG 上
-
我认为这是 postgres 9.1 和 9.0 之间的区别。尝试在 heroku 上更新您的版本:devcenter.heroku.com/articles/upgrading-postgres-versions
-
postgres 更新仅适用于专用数据库,因为我仍在开发中,所以我正在使用共享数据库..
-
尝试使用 heroku 共享 postgressql 插件:devcenter.heroku.com/articles/heroku-shared-postgresql
标签: ruby-on-rails ruby-on-rails-3 activerecord heroku