Opened 12 years ago
Closed 2 years ago
#21547 closed Cleanup/optimization (fixed)
GeoDjango admin throws ProgrammingError after following the tutorial
| Reported by: | 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
- Visit the GeoDjango tutorial for Django 1.6 https://docs.djangoproject.com/en/1.6/ref/contrib/gis/tutorial/
- 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
- Create the "world" app described https://docs.djangoproject.com/en/1.6/ref/contrib/gis/tutorial/#create-a-new-project
- Follow the steps up to Put your data on the map. Run
python manage.py runserver.
- 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 worldis 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 (8)
comment:1 by , 12 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Bug → Cleanup/optimization |
follow-up: 3 comment:2 by , 12 years ago
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 by , 12 years ago
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 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:5 by , 11 years ago
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?
comment:6 by , 2 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → new |
I am having the same problem 9 years later. Sorry if this has been fixed, but I am having trouble finding the solution.
comment:7 by , 2 years ago
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;
comment:8 by , 2 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Please don't reopen old tickets. By the way, try first to find help from support channels and only open tickets when you are sure Django itself has an issue.
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) namedmpolyand the models generated withogrinspectwhere the geometric field is namedgeom. 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
sqlalloutput, the difference depends on thePostGisversion used. So we should also add a note. Accepting at least for that documentation issue.