[Django] #23902: Migrating between Geography / Geometry types fails

15 views
Skip to first unread message

Django

unread,
Nov 24, 2014, 5:48:47 AM11/24/14
to django-...@googlegroups.com
#23902: Migrating between Geography / Geometry types fails
----------------------------+--------------------
Reporter: mitchell | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
Adding or removing the "{{{geography=True}}}" argument to or from a GIS
column generates a migration which then fails to run because the columns
are two distinct types and cannot be converted between easily.

Exception:
{{{
Traceback (most recent call last):
File "bin/django", line 9, in <module>
load_entry_point('myproject==1.0.0', 'console_scripts', 'django')()
File "/home/mitchell/myproject/myproject/manage.py", line 19, in main
execute_from_command_line(argv)
File "/home/mitchell/myproject/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "/home/mitchell/myproject/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/mitchell/myproject/local/lib/python2.7/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/mitchell/myproject/local/lib/python2.7/site-
packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/mitchell/myproject/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/mitchell/myproject/local/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "/home/mitchell/myproject/local/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "/home/mitchell/myproject/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/mitchell/myproject/local/lib/python2.7/site-
packages/django/db/migrations/operations/fields.py", line 139, in
database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/mitchell/myproject/local/lib/python2.7/site-
packages/django/db/backends/schema.py", line 459, in alter_field
raise ValueError("Cannot alter field %s into %s - they do not properly
define db_type (are you using PostGIS 1.5 or badly-written custom
fields?)" % (
ValueError: Cannot alter field main.Venue.coordinates into
main.Venue.coordinates - they do not properly define db_type (are you
using PostGIS 1.5 or badly-written custom fields?)
}}}

Django 1.7.1.

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

Django

unread,
Nov 24, 2014, 8:17:25 AM11/24/14
to django-...@googlegroups.com
#23902: Migrating between Geography / Geometry types fails
--------------------------+--------------------------------------

Reporter: mitchell | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Do you have a suggestion on how we should proceed?

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

Django

unread,
Nov 25, 2014, 7:01:05 PM11/25/14
to django-...@googlegroups.com
#23902: Migrating between Geography / Geometry types fails
--------------------------+------------------------------------

Reporter: mitchell | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* stage: Unreviewed => Accepted


Comment:

Maybe a better error message is needed; I am not quite sure.

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

Django

unread,
Dec 2, 2016, 7:28:07 AM12/2/16
to django-...@googlegroups.com
#23902: Migrating between Geography / Geometry types fails
--------------------------+------------------------------------

Reporter: mitchell | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Sergey Fedoseev):

It seems that it's fixed in #25002.

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

Django

unread,
Nov 18, 2019, 12:36:33 PM11/18/19
to django-...@googlegroups.com
#23902: Migrating between Geography / Geometry types fails
--------------------------+------------------------------------

Reporter: mitchell | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Victor Munene):

This isn't fixed. Migrating a geometry field to geography works but the
other way round doesn't, including reversing a geometry -> geography
migration.

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

Django

unread,
Oct 22, 2020, 7:09:57 AM10/22/20
to django-...@googlegroups.com
#23902: Migrating between Geography / Geometry types fails
--------------------------+------------------------------------

Reporter: mitchell | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Mihail Cristian Dumitru):

Hello,

Any update on this? Or at least a temporary solution.

Thank you!

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

Django

unread,
Oct 22, 2020, 9:30:25 AM10/22/20
to django-...@googlegroups.com
#23902: Migrating between Geography / Geometry types fails
--------------------------+------------------------------------

Reporter: mitchell | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Claude Paroz):

The temporary solution is a classic three-step migration:
1. Create a new column with the desired type.
2. Copy values from the legacy column to the new column with a data
migration.
3. Delete the legacy column (and maybe rename the new column if you want
to get back to the initial column name).

Similar to #28809.

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

Reply all
Reply to author
Forward
0 new messages