0

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!

Community
  • 1
  • 1
sonobenissimo
  • 191
  • 4
  • 14
  • Assuming that you've migrated with `heroku run rake db:migrate`, try a raw sql query `Apartment.find_by_sql("SELECT apartments.* FROM apartments WHERE (bed = 0)")` just to see if it works. Also, not that this should be causing the error, but why not follow convention and use lower-case for column names? – cdesrosiers Nov 19 '12 at 22:02
  • @cdesrosiers Unfortunately the raw sql didn't do anything, still returning the same error. Also the column was all lower-case but I just figured I'd test to see if capitalizing might fix the issue which as you said was not the cause of the error. – sonobenissimo Nov 20 '12 at 00:39

1 Answers1

0

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/

stupied4ever
  • 353
  • 3
  • 7