Rails - gmaps4rails gem on postgres

不羁岁月 提交于 2019-11-28 14:24:46

Looks like PostgreSQL is complaining about this:

30.1926300 - venues.latitude

and the error message says that there is no operator that allows you to subtract a string from a number. I'd guess that you've created your venues.latitude column as a :string when it should be a :float or :decimal. MySQL tries to be friendly be doing a lot of implicit type conversions behind your back, PostgreSQL tries to be friendly by making you say exactly what you mean to avoid confusion.

You're going to have to change your latitude column to a numeric type. Then you should start developing on top of PostgreSQL if you're going to deploy on top of Heroku's PostgreSQL, you should also match the PostgreSQL version in your development and deployment environments.

AFAIK, you'll have to change the type manually with an ALTER TABLE as a simple change_column in a migration will probably fail with an error similar to

column "latitude" cannot be cast to type double precision

A migration like this:

def up
    connection.execute(%q{
        alter table venues
        alter column latitude
        type float using latitude::float
    })
end

should do the trick for PostgreSQL. Presumably you'll have to fix venues.longitude as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!