Opened 6 years ago

Last modified 9 months ago

#23902 new Bug

Migrating between Geography / Geometry types fails

Reported by: mitchell Owned by: nobody
Component: GIS Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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.


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/", line 19, in main
  File "/home/mitchell/myproject/local/lib/python2.7/site-packages/django/core/management/", line 385, in execute_from_command_line
  File "/home/mitchell/myproject/local/lib/python2.7/site-packages/django/core/management/", line 377, in execute
  File "/home/mitchell/myproject/local/lib/python2.7/site-packages/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/mitchell/myproject/local/lib/python2.7/site-packages/django/core/management/", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/mitchell/myproject/local/lib/python2.7/site-packages/django/core/management/commands/", 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/", line 63, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/mitchell/myproject/local/lib/python2.7/site-packages/django/db/migrations/", line 97, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/home/mitchell/myproject/local/lib/python2.7/site-packages/django/db/migrations/", 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/", 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/", 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.

Change History (4)

comment:1 Changed 6 years ago by Tim Graham

Do you have a suggestion on how we should proceed?

comment:2 Changed 6 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

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

comment:3 Changed 4 years ago by Sergey Fedoseev

It seems that it's fixed in #25002.

comment:4 Changed 9 months ago 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.

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