5

when trying to run migration to add a spatial index, get

Unknown key: spatial/Users/ME/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.2/lib/active_support/core_ext/hash/keys.rb:70:in `block in assert_valid_keys'

Using

  • Ruby 2.0.353
  • Rails 4.0.2
  • RGEO 0.3.20
  • RGEO Active Record 0.4.6
  • List item
  • activerecord-mysql2spatial-adapter 0.4.3

Migration Index file looks like

class CreateAddresses < ActiveRecord::Migration
  def change
    create_table :addresses, :options => 'ENGINE=MyISAM' do |t|
      t.string :street_1
      t.string :street2
      t.string :city
      t.string :state
      t.string :zip
      t.string :country
      t.string :full_address
      t.column :latlon, :point, :null => false

      t.timestamps
    end
    add_index :addresses, :latlon, :spatial => true
  end
end

UPDATE

Corrected this and other errors when I changed the adapter in my database.yml file from mysql2 to mysql2spatial

pcasa
  • 3,710
  • 7
  • 39
  • 67
  • 1
    I wish I could have up voted this 15 times! Should really be documented somewhere explicitly. Making an issue on GitHub now. Cheers. Update: https://github.com/dazuma/activerecord-mysql2spatial-adapter/issues/10 – Patelify Mar 28 '14 at 08:36
  • Resolved by me in https://github.com/rgeo/activerecord-mysql2spatial-adapter/pull/15 – januszm Aug 10 '15 at 11:40
  • 3
    I hit the same error with the postgis adapter. Coudn't work out why `spatial: true` stopped working in my `add_index` command (I even have that still in some of my older migrations). Not really a proper solution, but It seems like specifying `using: :gist` in its place has got the migration working as desired – Harry Wood Oct 11 '16 at 22:46
  • 1
    @HarryWood looks like `using: :gist` instead of `spatial: true` actually is the proper solution - see https://github.com/rgeo/activerecord-postgis-adapter#creating-spatial-tables – Yarin Dec 23 '16 at 19:04

0 Answers0