Rails - gmaps4rails gem on postgres

后端 未结 1 1220
粉色の甜心
粉色の甜心 2020-12-12 04:26

I successfully use the gmaps4rails gem on my local MySQL machine. However, when I deploy to PG on Heroku, I get the following error with respect to code that uses the gmaps4

相关标签:
1条回答
  • 2020-12-12 05:10

    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.

    0 讨论(0)
提交回复
热议问题