我为我的应用程序开发的这个页面在本地运行良好(使用 sqllite3),但是当我将它推送到使用 PostgreSQL 的 Heroku 时,我收到此错误:
NeighborhoodsController# (ActionView::Template::Error) "PGError: ERROR: column \"isupforconsideration\" does not exist\nLINE 1: ... \"photos\" WHERE (neighborhood = 52 AND isUpForCon...\n
从这行代码:
@photos = Photo.where(["neighborhood = ? AND isUpForConsideration = ?", @neighborhood.id, 1])
isUpForConsideration 无疑是照片专栏的一部分。我所有的迁移都是最新的,当我在本地拉回数据库时,isUpForConsideration 仍然存在,并且该应用程序仍在本地运行。
我也试过:
@photos = @neighborhood.photos(:conditions => {:isUpForConsideration => 1})
和
@photos = @neighborhood.photos.where(["isUpForConsideration = 1"])
这给了我这个错误:
NeighborhoodsController# (ActionView::Template::Error) "PGError: ERROR: column \"isupforconsideration\" does not exist\nLINE 1: ...tos\" WHERE (\"photos\".neighborhood = 52) AND (isUpForCon...\n
知道我可能做错了什么吗?
最佳答案
你的问题是table and column names are case sensitive in PostgreSQL .这通常是通过在进行查询时自动将它们转换为全小写来隐藏的(因此你会看到报告“isupforconsideration”的错误消息),但是如果你设法在创建时避开这种转换(通过双引号引起来,就像 Rails 所做的那样)当你创建一个表时),你会看到这种奇怪的现象。在 WHERE 子句中使用它时,您需要将“isUpForConsideration”用双引号括起来以解决此问题。
例如
@photos = @neighborhood.photos.where(["\"isUpForConsideration\" = 1"])
关于ruby-on-rails - Rails 和 Heroku PGError : column does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3902432/