Rails + PostGIS错误迁移数据库

tom*_*opp 12 postgresql postgis ruby-on-rails geolocation geospatial

我跟随Daniel Azuma关于使用rails进行地理空间分析的讨论,但每当我rake db:migrate在第二个项目中运行时,我都遇到了困难.

我的设置细节如下:我使用Postgres.app运行Postgresql,它给出了Postgres版本9.1.3和PostGIS 2.0.0版本.我遇到了database.yml文件的一些问题,并运行了迁移.(我添加了相关的宝石,并在application.rb中要求他们的信息)

我的database.yml文件如下所示:

 development:
   adapter: postgis
   postgis_extension: true
   host: localhost
   encoding: unicode
   database: my_app_development
   pool: 5
   username: my_app
   password:
Run Code Online (Sandbox Code Playgroud)

如果我添加以下行,schema_search_path: "public,postgis"我得到:

 rake aborted!
 PG::Error: ERROR:  schema "postgis" does not exist
 : SET search_path TO public,postgis
Run Code Online (Sandbox Code Playgroud)

如果我删除该行,当我尝试迁移数据库时收到以下错误:

rake aborted!
PG::Error: ERROR:  relation "geometry_columns" does not exist
LINE 1: SELECT * FROM geometry_columns WHERE f_table_name='schema_mi...                       ^
: SELECT * FROM geometry_columns WHERE f_table_name='schema_migrations'
Run Code Online (Sandbox Code Playgroud)

有没有人知道如何解决这些问题?

Rai*_*ido 18

在公共模式中删除PostGIS扩展并在postgis模式中重新创建它.

DROP EXTENSION PostGIS;

CREATE SCHEMA postgis;
CREATE EXTENSION PostGIS WITH SCHEMA postgis;
GRANT ALL ON postgis.geometry_columns TO PUBLIC;
GRANT ALL ON postgis.spatial_ref_sys TO PUBLIC
Run Code Online (Sandbox Code Playgroud)


tom*_*opp 10

这是我如何解决这个问题.我首先创建了一个新的迁移,将postgis添加到数据库中.(我已经在mac上通过自制软件安装了postgis和postgresql.)

rails g migration add_postgis_to_database
Run Code Online (Sandbox Code Playgroud)

在迁移文件中,我删除了更改方法,并使用execute方法添加POSTGIS.

execute("CREATE EXTENSION postgis;")
Run Code Online (Sandbox Code Playgroud)

之后,您可以检查数据库以确保postgis可用.

psql your_database_name
SELECT PostGIS_full_version();
Run Code Online (Sandbox Code Playgroud)