我想要使用PostgreSQL中存在的点类型类型。我做:Rails移植中的PostgreSQL点类型
rails g model Test point:point
产生的迁移:
class CreateTests < ActiveRecord::Migration
def change
create_table :tests do |t|
t.point :point
t.timestamps
end
end
end
当我运行:
rake db:migrate
结果是:
== CreateTests: migrating ====================================================
-- create_table(:tests)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `point' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0x000000038991a0>/home/i/Dropbox/programming/ruby/rails_pg_for_tests/db/migrate/20140306151700_create_tests.rb:4:in `block in change'
/home/i/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:184:in `create_table'
/home/i/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-4.0.2/lib/active_record/migration.rb:625:in `block in method_missing'
/home/i/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `block in say_with_time'
...
可能我需要安装PostGIS,但我不明白什么,如果我有点键入PostgreSQL。我只需要存储经纬度而无需其他选项。
我该如何使用这种点型或在这种情况下使用哪种更好?
谢谢。
仅仅因为PostgreSQL有一个点类型,并不意味着ActiveRecord的支持它。 – sevenseacat
'point'类型来自PostgreSQL,与PostGIS的'geometry'类型无关。 –