Postgis / Geodjango: Cannot determine PostGIS version for database
I'm attempting to launch a GeoDjango app. I've installed Postgres & PostGIS using brew on Lion. I created a database using template_postgis: createdb -T template_postgis test
.
When I run python manage.py syncdb
, I get the following error:
django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "test". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?
How can I track down the source of the error? I've checked that the user & pass in the config have access to the database etc.
As a first debugging step: try to check the postgis template version manually, eg on the command-line connect to your database with psql test
, and query with select postgis_lib_version();
. This function should be defined in template_postgis and return some number. Example output:
$ psql test
psql (9.0.4)
Type "help" for help.
test=# select postgis_lib_version();
postgis_lib_version
---------------------
1.5.2
(1 row)
If an error occurs, you know the error is in the database.
Just add in your settings.py your right version of postgis :
POSTGIS_VERSION = (2, 0, 3)
The solution for me was to run the following in the postgres terminal:
psql database_name
database_name=# CREATE EXTENSION postgis;
If you get ERROR: relation "spatial_ref_sys" already exists
, run the following before CREATE EXTENSION postgis
:
drop table spatial_ref_sys;
drop table geometry_columns;
链接地址: http://www.djcxy.com/p/79498.html