我的PostGIS数据库看起来不错,但GeoDjango认为不是......为什么?

Phi*_*ord 11 django postgresql postgis geodjango

我正在尝试设置一个GeoDjango应用程序来测试我遇到的早期问题.我已经建立了一个postgresql数据库,创建了一个新的Django项目和应用程序,但是当我尝试时./manage.py syncdb我得到了这个:

django.core.exceptions.ImproperlyConfigured:无法确定数据库"django_geotest"的PostGIS版本.GeoDjango至少需要PostGIS 1.3版.是否从空间数据库模板创建了数据库?

我不明白,因为我之前已经完成了GeoDjango的所有安装要求,并django_geotest通过这样做创建了这个数据库:

$ createdb -T template_postgis django_geotest
Run Code Online (Sandbox Code Playgroud)

看起来数据库设置正确:

django_geotest=# SELECT PostGIS_full_version();
                                     postgis_full_version                                          
-------------------------------------------------------------------------------------------------------
 POSTGIS="1.5.3" GEOS="3.2.2-CAPI-1.6.2" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.3" USE_STATS
(1 row)
Run Code Online (Sandbox Code Playgroud)

描述数据库,我得到这个:

django_geotest=# \d                
             List of relations
 Schema |       Name        | Type  | Owner 
--------+-------------------+-------+-------
 public | geography_columns | view  | phil
 public | geometry_columns  | table | phil
 public | spatial_ref_sys   | table | phil
(3 rows)
Run Code Online (Sandbox Code Playgroud)

所以现在我不知道接下来要尝试什么...我对postgresql及其模板等的了解并不是那么好.有任何想法吗?谢谢.

Ben*_*der 18

使用自制程序在OS X 10.9.1上安装PostgreSQL 9.3和PostGIS 2.1时遇到了同样的问题.

对于此特定问题,您只需添加以下行:

POSTGIS_VERSION = ( 2, 1 )
Run Code Online (Sandbox Code Playgroud)

使用逗号分隔的数字为您的PostGIS版本settings.py.

我不知道为什么,但是Django无法从PostGIS中读取版本信息.


Mar*_*air 5

每当我在一个类似的情况得到这个错误时(即数据库似乎是一个完全有效的PostGIS数据库)已经证明,有许多人在错误DATABASESsettings.py.它实际上是在连接到数据库失败时的身份验证,但只是在启动我的GeoDjango项目时触及数据库的第一件事就是postgis_lib_version来自django/contrib/gis/db/backends/postgis/operations.py