在rails 2项目上运行rake命令时出错

时间:2012-02-17 09:36:04

标签: ruby-on-rails ruby postgresql rake postgis

我正在使用以下gems,georuby,spatial_adapter运行rails 2项目。 Postgres db作为后端。但我面临这个错误。我累了安装postgis但仍然得到这个。任何想法我应该尝试。这是一个rails 2.3项目,所以我缺少一些版本要求。声明似乎是正确的,我也把它抬起来。请帮忙。

[root@localhost webapp]# rake db:migrate 
(in /root/mysite/webapp)
==  CreatePlaces: migrating ===================================================
-- create_table(:places, {:id=>false})
   -> 0.0030s
-- execute("alter table places add primary key (id)")
NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index "places_pkey" for table "places"
   -> 0.1144s
-- execute("select AddGeometryColumn('public', 'places', 'point_geometry', 4326, 'POINT', 3)")
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR:  function addgeometrycolumn(unknown, unknown, unknown, integer, unknown, integer) does not exist
LINE 1: select AddGeometryColumn('public', 'places', 'point_geometry...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
: select AddGeometryColumn('public', 'places', 'point_geometry', 4326, 'POINT', 3)

由于

1 个答案:

答案 0 :(得分:2)

我没有将post gis与postgres联系起来。因此面临着这个问题。

按照以下步骤首先创建数据库。

创建PostGIS数据库的第一步是创建一个简单的PostgreSQL数据库。

createdb [yourdatabase]

Many of the PostGIS functions are written in the PL/pgSQL procedural language. As such, the next step to create a PostGIS database is to enable the PL/pgSQL language in your new database. This is accomplish by the command

createlang plpgsql [yourdatabase]

Now load the PostGIS object and function definitions into your database by loading the postgis.sql definitions file (located in [prefix]/share/contrib as specified during the configuration step).

psql -d [yourdatabase] -f postgis.sql

For a complete set of EPSG coordinate system definition identifiers, you can also load the spatial_ref_sys.sql definitions file and populate the spatial_ref_sys table. This will permit you to perform ST_Transform() operations on geometries.

psql -d [yourdatabase] -f spatial_ref_sys.sql

If you wish to add comments to the PostGIS functions, the final step is to load the postgis_comments.sql into your spatial database. The comments can be viewed by simply typing \dd [function_name] from a psql terminal window.

psql -d [yourdatabase] -f postgis_comments.sql