Rails + PostGIS errors migrating database

tomciopp picture tomciopp · Aug 30, 2012 · Viewed 8.2k times · Source

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.

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)

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:

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?

Answer

Raido picture Raido · Sep 28, 2012

Drop PostGIS extenion in public schema and recreate it in postgis schema.

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