Rails + PostGIS错误迁移数据库 [英] Rails + PostGIS errors migrating database
问题描述
我正在关注Daniel Azuma关于使用rails进行地理空间分析,但当我在第二个项目中运行 rake db:migrate
时遇到了困难。
I was following Daniel Azuma's talk on geospatial analysis with rails but I am having difficulty whenever I run rake db:migrate
in the second project.
我的设置细节如下:我使用 Postgres.app 运行Postgresql,它给我的版本Postgres 9.1.3和PostGIS 2.0.0。我遇到了一些与database.yml文件有关的问题,并且正在运行迁移。 (我添加了相关的gem,并在application.rb中需要他们的信息)
The details of my setup are as follows: I am running Postgresql using Postgres.app which gives me version 9.1.3 of Postgres and 2.0.0 of PostGIS. I run into a few issues with the database.yml file, and running migrations. ( I have added the relevant gems and required their info in application.rb)
我的database.yml文件如下所示:
My database.yml file looks like this:
development:
adapter: postgis
postgis_extension: true
host: localhost
encoding: unicode
database: my_app_development
pool: 5
username: my_app
password:
如果我添加以下行 schema_search_path:public,postgis
我得到:
If I add the following line schema_search_path: "public,postgis"
I get:
rake aborted!
PG::Error: ERROR: schema "postgis" does not exist
: SET search_path TO public,postgis
如果我删除该行,当尝试迁移我的数据库时收到以下错误:
If I remove that line I receive the following error when I try to migrate my database:
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'
有没有人有解决这些问题的方法?
Does anyone have an idea on how to fix these issues?
推荐答案
这是我解决问题的方法。我首先创建了一个新的迁移来添加postgis到数据库。 (我已经在Mac上通过自制软件安装了postgis和postgresql。)
Here is how I solved the issue. I first created a new migration to add postgis to the database. (I have already installed both postgis and postgresql through homebrew on a mac.)
rails g migration add_postgis_to_database
在迁移文件中,我移除了更改方法,并使用execute方法添加POSTGIS。
In the migration file I removed the change method and used the execute method to add POSTGIS.
execute("CREATE EXTENSION postgis;")
After that you can check the database to make sure that postgis is available.
psql your_database_name
SELECT PostGIS_full_version();
这篇关于Rails + PostGIS错误迁移数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!