geodjango with postgis would not work

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.


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:

  • Are all the apt system dependencies are installed? See Step 1 from the article.
  • When you created the postgis_template schema, did run the commands to create the geospacial database objects (See Step 2 of attached link)?
  • Is a fairly recent version of PostGIS installed? Check the minimum requirements at: https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#spatial-database
  • Anyway, hope this helps. Joe

    链接地址: http://www.djcxy.com/p/79500.html

    上一篇: jQuery许可选择

    下一篇: 与postgis geodjango不会工作