【问题标题】:Trouble adding st_point column with activerecord-postgis-adapter使用 activerecord-postgis-adapter 添加 st_point 列时遇到问题
【发布时间】:2017-05-14 23:54:15
【问题描述】:

这是我在project github 上写的内容的完整副本。请原谅我的交叉发帖,但我希望这里有人遇到了这个错误:

undefined method `st_point' for #
<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x0055cdd8f278e8>

这是我的 Gemfile 锁:

activerecord (4.2.7.1)
activerecord-postgis-adapter (3.1.4)

以及迁移:

class CreateLocations < ActiveRecord::Migration
  def change
    enable_extension "postgis"
    create_table :locations do |t|
      t.st_point :geom, geographic: true, srid: 4326, dimension: 2
      t.timestamps
    end
  end
end

奇怪的是这在开发模式下有效。只是当我为测试环境运行迁移时它失败了。

rake db:create RAILS_ENV=test 之后,我使用psql 连接到测试数据库并运行CREATE EXTENSION postgis;

tl;dr

t.st_point在迁移中是未定义的,只在测试环境中。

【问题讨论】:

    标签: ruby-on-rails ruby postgresql activerecord postgis


    【解决方案1】:

    错误是 ENV["DATABASE_URL"] 中的“postgres”而不是“postgis”

    这是其他人在线程上建议的。我很固执,没有检查这个,但事实证明这是正确的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 2014-10-07
      相关资源
      最近更新 更多