Opened 20 months ago

Closed 19 months ago

Last modified 15 months ago

#21547 closed Cleanup/optimization (fixed)

GeoDjango admin throws ProgrammingError after following the tutorial

Reported by: awilliams@… Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords: geodjango, gis, postgis 2.0
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi guys. This is my first bug report so please let me know how I can improve it. I'm still new to the world of GeoDjango, but I did successfully upgrade an existing GeoDjango 1.5 application to 1.6 without any hiccups. I'm only seeing this problem when I create a new projects. This is using the default Django 1.6 project and app structure.

The Problem

The GeoDjango admin for the "world" app created in the GeoDjango tutorial throws a ProgrammingError:

ProgrammingError at /admin/world/worldborder/
column world_worldborder.geom does not exist
LINE 1: ...ld_worldborder"."lon", "world_worldborder"."lat", "world_wor...

Reproduce the problem

  1. Visit the GeoDjango tutorial for Django 1.6 https://docs.djangoproject.com/en/1.6/ref/contrib/gis/tutorial/
  1. Create a database with GIS extensions https://docs.djangoproject.com/en/1.6/ref/contrib/gis/install/postgis/#creating-a-spatial-database-with-postgis-2-0-and-postgresql-9-1
  1. Create the "world" app described https://docs.djangoproject.com/en/1.6/ref/contrib/gis/tutorial/#create-a-new-project
  1. Follow the steps up to Put your data on the map. Run python manage.py runserver .
  1. Visit http://127.0.0.1:8000/admin/world/worldborder/ to see the error.

Notes

  • Most of the tutorial works as described. it's only the admin section that throws an error.
  • The output from python manage.py sqlall world is different than the tutorial:
    BEGIN;
    CREATE TABLE "world_worldborder" (
        "id" serial NOT NULL PRIMARY KEY,
        "name" varchar(50) NOT NULL,
        "area" integer NOT NULL,
        "pop2005" integer NOT NULL,
        "fips" varchar(2) NOT NULL,
        "iso2" varchar(2) NOT NULL,
        "iso3" varchar(3) NOT NULL,
        "un" integer NOT NULL,
        "region" integer NOT NULL,
        "subregion" integer NOT NULL,
        "lon" double precision NOT NULL,
        "lat" double precision NOT NULL,
        "mpoly" geometry(MULTIPOLYGON,4326) NOT NULL
    )
    ;
    CREATE INDEX "world_worldborder_mpoly_id" ON "world_worldborder" USING GIST ( "mpoly" );
    
    COMMIT;
    
    

Output in tutorial: https://docs.djangoproject.com/en/1.6/ref/contrib/gis/tutorial/#run-syncdb

Development setup

  • Ubuntu 12.10
  • Python 2.7.3
  • Django 1.6
  • PostGIS 2.0.1
  • PostgreSQL 9.1.10
  • Virtualenvwrapper 4.1.1
  • Virtualenv 1.10.1

The stacktrace:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/world/worldborder/

Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.gis',
 'world')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  430.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  25.                 return func(self, *args2, **kwargs2)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in changelist_view
  1409.             'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
  77.         self._fetch_all()
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
  854.             self._result_cache = list(self.iterator())
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  220.         for row in compiler.results_iter():
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
  710.         for rows in self.execute_sql(MULTI):
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  781.         cursor.execute(sql, params)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  69.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  53.                 return self.cursor.execute(sql, params)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  99.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/aaron/Envs/development/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  53.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /admin/world/worldborder/
Exception Value: column world_worldborder.geom does not exist
LINE 1: ...ld_worldborder"."lon", "world_worldborder"."lat", "world_wor...
                                                             ^

Change History (5)

comment:1 Changed 20 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

Thanks for the detailed report, the form is good :-)

I think the problem comes from the difference between models generated with LayerMapping, where the geometric field is (manually) named mpoly and the models generated with ogrinspect where the geometric field is named geom. The model definition should match the method used to produce the database table, being one or the other.

This might deserve a short notice in the tutorial. Also for the sqlall output, the difference depends on the PostGis version used. So we should also add a note. Accepting at least for that documentation issue.

Last edited 20 months ago by claudep (previous) (diff)

comment:2 follow-up: Changed 20 months ago by bowenii_clinton@…

I believe I am running into the same problem; and I apologize if this comment is not of any use this is my first time reporting/commenting on a bug.

Using the same setup as the bug reporter, I get the following from running "python manage.py sqlall world"

BEGIN;
CREATE TABLE "world_worldborder" (

"id" serial NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL,
"area" integer NOT NULL,
"pop2005" integer NOT NULL,
"fips" varchar(2) NOT NULL,
"iso2" varchar(2) NOT NULL,
"iso3" varchar(3) NOT NULL,
"un" integer NOT NULL,
"region" integer NOT NULL,
"subregion" integer NOT NULL,
"lon" double precision NOT NULL,
"lat" double precision NOT NULL,
"mpoly" geometry(MULTIPOLYGON,4326) NOT NULL

)

;
CREATE INDEX "world_worldborder_mpoly_id" ON "world_worldborder" USING GIST ( "mpoly" );
COMMIT;

Whis is the same as the bug reporter. So the value GIST_GEOMETRY_OPS is not shown as is shown on https://docs.djangoproject.com/en/dev/ref/contrib/gis/tutorial/#introduction

If I am reading this correctly on http://trac.osgeo.org/postgis/ticket/1287 , I beleive GIST_GEOMETRY_OPS is not a an operator anymore in POSTGIS version 2.0 and higher. Maybe this is what claudep meant by "the difference depends on the PostGis version used."

Any ideas on what should be done about this?

comment:3 in reply to: ↑ 2 Changed 20 months ago by claudep

Replying to bowenii_clinton@…:
...

If I am reading this correctly on http://trac.osgeo.org/postgis/ticket/1287 , I beleive GIST_GEOMETRY_OPS is not a an operator anymore in POSTGIS version 2.0 and higher. Maybe this is what claudep meant by "the difference depends on the PostGis version used."

Any ideas on what should be done about this?

Yes, some syntax has changed in PostGIS 2. So the documentation should be amended consequently (noting possible difference with PostGIS 2).

comment:4 Changed 19 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 3d4ed28dce851beab8f679190fc91366742bca68:

Fixed #21547 -- Updated GeoDjango tutorial with PostGIS 2 output

Thanks awilliams at cironline.org for the report.

comment:5 Changed 15 months ago by anonymous

I remain confused about this error. I get the exact same error following the tutorial using django 1.6 & postgis 2.1.1. Can anyone elaborate on a solution?

Note: See TracTickets for help on using tickets.
Back to Top