Search code examples
ruby-on-railsactiverecordherokuwhere-clausepg

Recurring Heroku PG Active Record Error, "column does not exist"


So, this is now the third time I've received this error over the course of working on this project I posted a question a few months back regarding this 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

Controller Code

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

Basically, I was able to fix it the first two times by switching from find to where and then the second time from where back to find. I could never make sense why it worked but it did so I wound up forgetting about it until I started getting the error again. Now it whether I swap between where/find searches I still wind up with the same error. Any help would be highly welcomed I'm a bit lost on what the cause of this issue might be.

Thanks in advance!


Solution

  • Have u created the bed column by one add column migration? if yes try this

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