2012-10-29 84 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