Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails and Heroku PGError: column does not exist

This page I have been developing for my app has been working fine locally (using sqllite3) but when I push it to Heroku, which uses PostgreSQL I get this error:

NeighborhoodsController# (ActionView::Template::Error) "PGError: ERROR: column \"isupforconsideration\" does not exist\nLINE 1: ... \"photos\" WHERE (neighborhood = 52 AND isUpForCon...\n

From this line of code:

@photos = Photo.where(["neighborhood = ? AND isUpForConsideration = ?", @neighborhood.id, 1])

isUpForConsideration is defiantly part of the Photo column. All my migrations are up to date, and when I pull the db back locally isUpForConsideration is still there, and the app still works locally.

I've also tried:

@photos = @neighborhood.photos(:conditions => {:isUpForConsideration => 1})

and

@photos = @neighborhood.photos.where(["isUpForConsideration = 1"])

Which gives me this error:

NeighborhoodsController# (ActionView::Template::Error) "PGError: ERROR: column \"isupforconsideration\" does not exist\nLINE 1: ...tos\" WHERE (\"photos\".neighborhood = 52) AND (isUpForCon...\n

Any idea what I could be doing wrong?

like image 668
dpieri Avatar asked Dec 01 '22 04:12

dpieri


1 Answers

Your problem is that table and column names are case sensitive in PostgreSQL. This is normally hidden by automatically converting these to all-lowercase when making queries (hence why you see the error message reporting "isupforconsideration"), but if you managed to dodge that conversion on creation (by double quoting the name, like Rails does for you when you create a table), you'll see this weirdness. You need to enclose "isUpForConsideration" in double quotes when using it in a WHERE clause to fix this.

e.g.

@photos = @neighborhood.photos.where(["\"isUpForConsideration\" = 1"])
like image 86
Conspicuous Compiler Avatar answered Dec 04 '22 05:12

Conspicuous Compiler