11

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.

Community
  • 1
  • 1
Phil Gyford
  • 13,432
  • 14
  • 81
  • 143
  • I had the same problem before but I can't figure out how I solved it. I think I tried this: http://stackoverflow.com/questions/5907672/installation-error-while-trying-to-install-a-gis-application-using-geodjango – dannyroa May 14 '12 at 18:34
  • 1
    had the same problem with PostgreSQL 9.3 and PostGIS 2.1 installed on OS X 10.9.1 using homebrew, all I had to do was add `POSTGIS_VERSION = ( 2, 1 )` to `settings.py`. It simply couldn't read the setting – BenjaminGolder Jan 16 '14 at 20:22
  • @BenjaminGolder - that solved my problem as well... Suggest it should be the correct answer? – Erve1879 Feb 11 '14 at 12:40

3 Answers3

18

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.

BenjaminGolder
  • 1,573
  • 5
  • 19
  • 37
5

Whenever I've got this error in a similar situation (i.e. when the database seems to be a perfectly valid PostGIS database) it has turned out that there's been an error in DATABASES in settings.py. It's actually authentication when connecting to the database failing, but it just happens that the first thing that touches the database when starting up my GeoDjango project is the postgis_lib_version call from django/contrib/gis/db/backends/postgis/operations.py

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
1

I had the same issue a couple months ago. I had to recreate the template_database and the main db again. From this link.

Maqsood
  • 478
  • 6
  • 10