3
votes

I am new to geodjango, I have the following settings:

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

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.gis',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django.contrib.gis',
    "app.core",
)

and I have created the db with following command:

postgres@rewitaqia:~$ createdb -U postgres -T template_postgis -O django dbname

but when I try to sync the db it says:

django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "dbname". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?

Also the when I try this in psql it seems that db tas not really created from postgis template:

db_name=# select postgis_lib_version();
ERROR:  no existe la función postgis_lib_version()
ŘÁDKA 1: select postgis_lib_version();
                ^
DOPORUČENÍ:  Ninguna función coincide en el nombre y tipos de argumentos. Puede desear agregar conversión explícita de tipos.

Thanks for reading anyway.

1
Are you sure you're connecting to the same database you createdb'd when you test with psql? Could there be two different ones with different case, or one with and one without an underscore? Connect with psql and run \l .Craig Ringer
Does your database have the tables 'geometry_columns' and 'spatial_ref_sys'?RickyA
@RickyA: No it seems that it does notVisgean Skeloru
@CraigRinger yes, they are same...Visgean Skeloru

1 Answers

4
votes

Visgean,

When setting up PostGIS for the first time, I had a lot of the same questions as you so I created an article detailing the PostGIS setup. Sorry to plug my own article, but I created it to help document the setup process. http://www.chicagodjango.com/blog/geo-django-quickstart/

Looking at your question above, it's hard to tell exactly what the issue is. However, things you might check that would produce that PostGIS error listed:

Anyway, hope this helps. Joe