【发布时间】:2014-03-06 15:47:33
【问题描述】:
我想使用 PostgreSQL 中的 point 类型。我已经完成了:
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 支持。
-
point类型来自 PostgreSQL,与 PostGIS 的geometry类型无关。
标签: ruby-on-rails ruby postgresql ruby-on-rails-4