My PostGIS database looks fine but GeoDjango thinks otherwise... why?

django, geodjango, postgis, postgresql

Solution

I had the same problem with PostgreSQL 9.3 and PostGIS 2.1 installed on OS X 10.9.1 using homebrew.

For this particular issue, you only need to add this line:

POSTGIS_VERSION = ( 2, 1 )

using the comma separated number for your PostGIS version to `settings.py`.

I'm not sure why, but Django's having trouble reading the version information from PostGIS.

Problem

I'm trying to set up a GeoDjango app to test an earlier problem I was having. I've set up a postgresql database, created a new Django project and app, but when I try `./manage.py syncdb` I get this: django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "django_geotest". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template? Which I don't understand as I've previously been through all the installation of GeoDjango's requirements, and created this `django_geotest` database by doing this: ``` $ createdb -T template_postgis django_geotest ``` And it looks like the database is correctly set up: ``` 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) ``` Describing the database, I get this: ``` 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) ``` So now I'm stuck as to what to try next... My knowledge of postgresql and its templates etc isn't that great. Any ideas? Thanks.

Original source