#23161 closed Uncategorized (fixed)
Migration to remove a GIS field causes exception
| Reported by: | James Aylett | Owned by: | Andrew Godwin |
|---|---|---|---|
| Component: | Migrations | Version: | 1.7-rc-2 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
A GIS model which contains a PointField:
from django.contrib.gis.db import models
class Event(models.Model):
...
location = models.PointField(geography=True, blank=True, null=True)
migrated to successfully, then removed with an autogenerated migration:
class Migration(migrations.Migration):
operations = [
migrations.RemoveField(
model_name='event',
name='location',
),
]
when applied (1.7rc2, postgresql 9.3, postgis 1.5.3) raises the following exception:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute
output = self.handle(*args, **options)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 84, in database_forwards
schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0])
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/schema.py", line 108, in remove_field
"column": self.geo_quote_name(field.column),
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 98, in execute
cursor.execute(sql, params)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/user/.virtualenvs/looseend/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.InternalError: column not found in geometry_columns table
CONTEXT: SQL statement "SELECT DropGeometryColumn('','',$1,$2)"
PL/pgSQL function "dropgeometrycolumn" line 5 at SQL statement
There is indeed nothing in geometry_columns, however running SELECT Probe_Geometry_Columns(); doesn't indicate a desire from postgis for there to be any either.
The migration fragment that created the column (which was under 1.7b4 I believe) is (as part of a migrations.CreateModel() call):
('location', django.contrib.gis.db.models.fields.PointField(srid=4326, geography=True)),
The entire app has been built under 1.7, and all project app DDL has gone through the migrations framework.
Change History (5)
comment:1 by , 11 years ago
| Severity: | Normal → Release blocker |
|---|
comment:2 by , 11 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:4 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Initial investigation leads me to believe this is only happening when
geography=true.