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,它为我提供了 9.1 版Postgres .3 和 PostGIS 2.0.0.我在 database.yml 文件和运行迁移时遇到了一些问题.(我已在 application.rb 中添加了相关的 gem 并要求提供他们的信息)
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 上通过 homebrew 安装了 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
在迁移文件中我去掉了change方法,用execute方法添加了POSTGIS.
In the migration file I removed the change method and used the execute method to add POSTGIS.
execute("CREATE EXTENSION postgis;")
之后,您可以检查数据库以确保 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屋!