重复Heroku PG活动记录错误,“列不存在”

时间:2012-11-19 21:45:32

标签: ruby-on-rails activerecord heroku where pg

所以,这是我第三次在这个项目的工作过程中收到这个错误我几个月前发布了一个问题 ActiveRecord::StatementInvalid (PG::Error: ERROR: column does not exist

Heroku Logs

2012-11-19T05:04:20+00:00 app[web.1]: Processing by MainController#home as HTML
2012-11-19T05:04:20+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms
2012-11-19T05:04:20+00:00 app[web.1]: 
2012-11-19T05:04:20+00:00 app[web.1]: LINE 1: SELECT "apartments".* FROM "apartments"  WHERE (Bed = 0)
2012-11-19T05:04:20+00:00 app[web.1]:                                                         ^
2012-11-19T05:04:20+00:00 app[web.1]:   app/controllers/main_controller.rb:6:in `home'
2012-11-19T05:04:20+00:00 app[web.1]: : SELECT "apartments".* FROM "apartments"  WHERE (Bed = 0)):
2012-11-19T05:04:20+00:00 app[web.1]: 
2012-11-19T05:04:20+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR:  column "bed" does not exist

控制器代码

def home
  @apartments = Apartment.all
  @studio = Apartment.where(:Bed => 0).all
  @oneBdr = Apartment.where(:Bed => 1).all
  @twoBdr = Apartment.where(:Bed => 2).all
  @threeBdr = Apartment.where(:Bed => 3).all
  @fourPlusBdr = Apartment.where("Bed >= 4").all
end

基本上,我能够通过从find切换到where然后第二次从返回到找到来解决前两次。我永远无法理解它为什么会起作用,但它确实如此,我忘记了它,直到我再次开始收到错误。现在,无论我在哪里/找到搜索之间切换,我仍然会遇到同样的错误。任何帮助都会受到高度欢迎我对这个问题的原因有点失落。

提前致谢!

1 个答案:

答案 0 :(得分:0)

您是否通过一次添加列迁移创建了床栏?如果是的话试试这个

http://blog.blazingcloud.net/2010/12/02/heroku-migration-fails-to-update-attributes-reset_column_information/