[Django] #21547: GeoDjango admin throws ProgrammingError after following the tutorial

68 views
Skip to first unread message

Django

unread,
Dec 2, 2013, 3:38:10 PM12/2/13
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------+-----------------------------------------
Reporter: awilliams@… | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Keywords: geodjango, gis, postgis 2.0
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
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/

2. 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

3. Create the "world" app described
https://docs.djangoproject.com/en/1.6/ref/contrib/gis/tutorial/#create-a
-new-project

4. Follow the steps up to '''Put your data on the map'''. Run {{{ python
manage.py runserver }}}.

5. 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:
{{{#!sql
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...
^
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21547>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 2, 2013, 5:10:45 PM12/2/13
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.6
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: geodjango, gis, | Needs documentation: 0
postgis 2.0 | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_better_patch: => 0
* needs_docs: => 0
* type: Bug => Cleanup/optimization
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:1>

Django

unread,
Dec 14, 2013, 6:06:09 PM12/14/13
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.6
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: geodjango, gis, | Needs documentation: 0
postgis 2.0 | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (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?

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:2>

Django

unread,
Dec 15, 2013, 5:38:51 AM12/15/13
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.6
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: geodjango, gis, | Needs documentation: 0
postgis 2.0 | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by claudep):

Replying to [comment:2 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).

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:3>

Django

unread,
Jan 11, 2014, 12:01:21 PM1/11/14
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.6
Component: Documentation | Resolution: fixed

Severity: Normal | Triage Stage: Accepted
Keywords: geodjango, gis, | Needs documentation: 0
postgis 2.0 | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"3d4ed28dce851beab8f679190fc91366742bca68"]:
{{{
#!CommitTicketReference repository=""
revision="3d4ed28dce851beab8f679190fc91366742bca68"
Fixed #21547 -- Updated GeoDjango tutorial with PostGIS 2 output

Thanks awilliams at cironline.org for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:4>

Django

unread,
May 21, 2014, 7:34:36 PM5/21/14
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody

Type: | Status: closed
Cleanup/optimization | Version: 1.6
Component: Documentation | Resolution: fixed
Severity: Normal | Triage Stage: Accepted
Keywords: geodjango, gis, | Needs documentation: 0
postgis 2.0 | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (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?

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:5>

Django

unread,
May 30, 2023, 8:42:22 AM5/30/23
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: geodjango, gis, | Triage Stage: Accepted
postgis 2.0 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bjoh-01):

* status: closed => new
* resolution: fixed =>


Comment:

I am having the same problem 9 years later. Sorry if this has been fixed,
but I am having trouble finding the solution.

I am using POSTGIS 3.0, django 4.2.1.

Traceback:

{{{

Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/core/management/__init__.py", line 442, in
execute_from_command_line
utility.execute()
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/core/management/commands/migrate.py", line 356, in handle
post_migrate_state = executor.migrate(
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/migrations/executor.py", line 167, in
_migrate_all_forwards
state = self.apply_migration(
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/migrations/migration.py", line 132, in apply
operation.database_forwards(
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/migrations/operations/models.py", line 96, in
database_forwards
schema_editor.create_model(model)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/base/schema.py", line 451, in create_model
self.execute(sql, params or None)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/postgresql/schema.py", line 45, in execute
return super().execute(sql, params)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/base/schema.py", line 201, in execute
cursor.execute(sql, params)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/vboxuser/Desktop/django/lib/python3.8/site-
packages/django/db/backends/utils.py", line 87, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: type "geometry" does not exist
LINE 1: ...OT NULL, "lat" double precision NOT NULL, "mpoly" geometry(M...

}}}


There is no longer a `sqlall` command, but running `python manage.py
sqlmigrate world 0001` yields:


{{{
BEGIN;
--
-- Create model WorldBorder
--
CREATE TABLE "world_worldborder" ("id" bigint NOT NULL PRIMARY KEY
GENERATED BY DEFAULT AS IDENTITY, "name" varchar(50) NOT NULL, "area"
integer NOT NULL, "pop2005" integer NOT NULL, "fips" varchar(2) 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_6f181651_id" ON "world_worldborder"


USING GIST ("mpoly");
COMMIT;
}}}

Replying to [ticket:21547 awilliams@…]:

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:6>

Django

unread,
May 30, 2023, 8:43:40 AM5/30/23
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: geodjango, gis, | Triage Stage: Accepted
postgis 2.0 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by bjoh-01):

GENERATED BY DEFAULT AS IDENTITY, "name" varchar(50) NOT NULL, "area"
integer NOT NULL, "pop2005" integer NOT NULL, "fips" varchar(2) 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_6f181651_id" ON "world_worldborder"


USING GIST ("mpoly");
COMMIT;
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:7>

Django

unread,
May 30, 2023, 8:58:45 AM5/30/23
to django-...@googlegroups.com
#21547: GeoDjango admin throws ProgrammingError after following the tutorial
-------------------------------------+-------------------------------------
Reporter: awilliams@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: geodjango, gis, | Triage Stage: Accepted
postgis 2.0 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* status: new => closed
* resolution: => fixed


Comment:

Please don't reopen old tickets. By the way, try first to find help from
[TicketClosingReasons/UseSupportChannels support channels] and only open
tickets when you are sure Django itself has an issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/21547#comment:8>

Reply all
Reply to author
Forward
0 new messages