2012-10-29 36 views
5

我正在使用geoDjango。我已经安装了源Gdal,proj1.4,geos3.3.5Postgis2.0.1的以下软件包。我是Ubuntu的用户。当我运行syncdb后,我得到以下错误。我错过了什么吗?感谢安装索引失败(Geodjango相关)

Superuser created successfully. 
Installing custom SQL ... 
Installing indexes ... 
Failed to install index for cities.City model: operator class "gist_geometry_ops" does not exist for access method "gist" 

Failed to install index for cities.District model: operator class "gist_geometry_ops" does not exist for access method "gist" 

Failed to install index for cities.PostalCodeCA model: operator class "gist_geometry_ops" does not exist for access method "gist" 

Installed 0 object(s) from 0 fixture(s) 

回答

2

你需要创建一个模板的PostGIS并装入培训相关postgis.sql

说你PostGIS的路径是/usr/share/postgresql/8.4/contrib 来看,这种

 

POSTGIS_SQL_PATH=/usr/share/postgresql/8.4/contrib 
sudo -u postgres createdb -E UTF8 template_postgis1 # Create the template spatial database. 
sudo -u postgres createlang -d template_postgis1 plpgsql # Adding PLPGSQL language support. 
sudo -u postgres psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis1';" 
sudo -u postgres psql -d template_postgis1 -f $POSTGIS_SQL_PATH/postgis.sql # Loading the PostGIS SQL routines 
sudo -u postgres psql -d template_postgis1 -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql 
sudo -u postgres psql -d template_postgis1 -c "GRANT ALL ON geometry_columns TO PUBLIC;" # Enabling users to alter spatial tables. 
sudo -u postgres psql -d template_postgis1 -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;" 



然后需要使用创建的模板创建您的数据库

 
sudo -u postgres createdb database_name -T template_postgis1 
+0

感谢您的回复。我改变了'POSTGIS_SQL_PATH'。但我变得一样。 X-( – Kulbir

+3

'''django1.4'不支持'Postgis2.0.1',我降级到'Postgis1.5'并运行你的命令,它工作正常,感谢您的帮助 – Kulbir

+1

我没有降级,但是在Jeasoft的答案中使用了template_postgis上的向后兼容性补丁 – BenjaminGolder

8

也许我有点晚,但我解决了这个问题(Django的1.4.x的,POSTGIS 2.0.1和PostgreSQL 9.2)在template_postgis数据库这样创建一个操作符:

CREATE OPERATOR CLASS gist_geometry_ops 
FOR TYPE geometry USING GIST AS 
STORAGE box2df, 
OPERATOR  1  << , 
OPERATOR  2  &< , 
OPERATOR  3  && , 
OPERATOR  4  &> , 
OPERATOR  5  >> , 
OPERATOR  6  ~= , 
OPERATOR  7  ~ , 
OPERATOR  8  @ , 
OPERATOR  9  &<| , 
OPERATOR  10  <<| , 
OPERATOR  11  |>> , 
OPERATOR  12  |&> , 

OPERATOR  13  <-> FOR ORDER BY pg_catalog.float_ops, 
OPERATOR  14  <#> FOR ORDER BY pg_catalog.float_ops, 
FUNCTION  8  geometry_gist_distance_2d (internal, geometry, int4), 

FUNCTION  1  geometry_gist_consistent_2d (internal, geometry, int4), 
FUNCTION  2  geometry_gist_union_2d (bytea, internal), 
FUNCTION  3  geometry_gist_compress_2d (internal), 
FUNCTION  4  geometry_gist_decompress_2d (internal), 
FUNCTION  5  geometry_gist_penalty_2d (internal, internal, internal), 
FUNCTION  6  geometry_gist_picksplit_2d (internal, internal), 
FUNCTION  7  geometry_gist_same_2d (geom1 geometry, geom2 geometry, internal); 

这是从该提取链接http://trac.osgeo.org/postgis/ticket/1287#comment:8

+0

+1这对我有帮助我输入了psql,切换到了postgis_template db然后运行这个 – BenjaminGolder

+0

谢谢,我花了很多时间在这个上面。 – ismailsunni