GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?

1,733 views
Skip to first unread message

Dhannababu Nyros

unread,
Oct 7, 2013, 10:53:13 AM10/7/13
to geod...@googlegroups.com
I am new to geodjango. My database settings as following below,

DATABASES = {
    "default": {
        "ENGINE": "django.contrib.gis.db.backends.postgis", # Add "postgresql_psycopg2", "postgresql", "mysql", "sqlite3" or "oracle".
        "NAME": "testdb",                       # Or path to database file if using sqlite3.
        "USER": "postgres",                             # Not used with sqlite3.
        "PASSWORD": "test",                         # Not used with sqlite3.
        "HOST": "localhost",                             # Set to empty string for localhost. Not used with sqlite3.
        "PORT": "",                             # Set to empty string for default. Not used with sqlite3.
    }
}

When I run the python manage.py syncdb. I got the below error,


Traceback (most recent call last):
  File "manage.py", line 27, in <module>
    execute_from_command_line()
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 217, in execute
    translation.activate('en-us')
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 105, in activate
    return _trans.activate(language)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 194, in activate
    _active.value = translation(language)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 183, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 160, in _fetch
    app = import_module(appname)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/nyros/hs/git_br/healersource/apps/messages_hs/__init__.py", line 2, in <module>
    from django.db.models import signals
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
    conn = backend.DatabaseWrapper(db, alias)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 11, in __init__
    self.ops = PostGISOperations(self)
  File "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.py", line 108, in __init__
    'template?' % self.connection.settings_dict['NAME']
django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "testdb". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?

Claude Paroz

unread,
Oct 8, 2013, 10:27:46 AM10/8/13
to geod...@googlegroups.com
Le lundi 07 octobre 2013 à 07:53 -0700, Dhannababu Nyros a écrit :
> I am new to geodjango. My database settings as following below,
>
>
> DATABASES = {
> "default": {
> "ENGINE": "django.contrib.gis.db.backends.postgis", # Add "postgresql_psycopg2", "postgresql", "mysql", "sqlite3" or "oracle".
> "NAME": "testdb", # Or path to database file if using sqlite3.
> "USER": "postgres", # Not used with sqlite3.
> "PASSWORD": "test", # Not used with sqlite3.
> "HOST": "localhost", # Set to empty string for localhost. Not used with sqlite3.

As stated in the comment, for "localhost", simply use the empty string
("").

> "PORT": "", # Set to empty string for default. Not used with sqlite3.
> }
> }
>
>
> When I run the python manage.py syncdb. I got the below error,
>
(...)
>
> "/home/nyros/hs/1a9pinaxenv/local/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.py", line 108, in __init__
> 'template?' % self.connection.settings_dict['NAME']
> django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS
> version for database "testdb". GeoDjango requires at least PostGIS
> version 1.3. Was the database created from a spatial database
> template?

If changing the HOST setting didn't fix your issue, check that your
database was created from the template_posgis template, as explained
here:
https://docs.djangoproject.com/en/1.5/ref/contrib/gis/tutorial/#create-a-spatial-database

Then you can also check that your are able to connect to your database
with the "psql" client, like this:

psql -U <username> -W <dbname>

Hope this helps.

Claude
--
www.2xlibre.net

pis...@gmail.com

unread,
Jul 24, 2014, 5:45:03 AM7/24/14
to geod...@googlegroups.com
You have to connect to the dabase using psql

 psql -U username -W testdb

then type

select postgis_lib_version();

to obtain the postgis version for the selected database

 postgis_lib_version
---------------------
 1.5.8

then add a line to the settings.py file with

    POSTGIS_VERSION = (1, 5, 8)
   
where the tuple (1, 5, 8) will be your version of postgis

I found this solution at this url
http://trapper.readthedocs.org/en/latest/troubleshooting.html

harrie...@gmail.com

unread,
Jun 18, 2015, 8:10:32 AM6/18/15
to geod...@googlegroups.com
Thanx alot it worked well.
Reply all
Reply to author
Forward
0 new messages