我正在尝试设置 Postgres 和 Postgis 在我的应用程序中执行一些简单的地理操作。我正在按照这篇文章的指示进行操作。一切都运行良好且快速。但是,当我运行rake db:migrate
或rake test
出现以下错误时:
psql:/Users/jophde/Desktop/local/db/structure.sql:154: ERROR: rule "geometry_columns_delete" for relation "geometry_columns" already exists
psql:/Users/jophde/Desktop/local/db/structure.sql:161: ERROR: rule "geometry_columns_insert" for relation "geometry_columns" already exists
psql:/Users/jophde/Desktop/local/db/structure.sql:168: ERROR: rule "geometry_columns_update" for relation "geometry_columns" already exists
它们更像是警告,因为测试和迁移工作正常。但是,每次测试时都打印出来非常烦人。我正在使用config.active_record.schema_format = :sql
. 这是错误中引用的行structure.sql
CREATE RULE geometry_columns_delete AS ON DELETE TO geometry_columns DO INSTEAD NOTHING;
CREATE RULE geometry_columns_insert AS ON INSERT TO geometry_columns DO INSTEAD NOTHING;
CREATE RULE geometry_columns_update AS ON UPDATE TO geometry_columns DO INSTEAD NOTHING;
我的数据库配置如下:
development:
adapter: postgresql
database: local_development
host: localhost
test:
adapter: postgresql
database: local_test
host: localhost
我用来启用 PostGis 的迁移是:
class EnablePostgis < ActiveRecord::Migration
def change
enable_extension :postgis
end
end
class AddPointIndexToMarkets < ActiveRecord::Migration
def up
execute %{
create index index_on_markets_location ON markets using gist (
ST_GeographyFromText(
'SRID=4326;POINT(' || markets.longitude || ' ' || markets.latitude || ')'
)
)
}
end
def down
execute %{ drop index index_on_markets_location }
end
end
我在 Mac OSX 10.8.4(Mountain Lion)上使用 Postgres.app 版本 9.3.0.0(16)(最新)