[Django] #28809: Changing SRID on geometry field doesn't create working migration

48 views
Skip to first unread message

Django

unread,
Nov 17, 2017, 1:57:06 AM11/17/17
to django-...@googlegroups.com
#28809: Changing SRID on geometry field doesn't create working migration
-------------------------------------+-------------------------------------
Reporter: Jani | Owner: nobody
Tiainen |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords: migrations gis
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When changing SRID of geometry field:

before:
{{{#!python
class AddressLog(models.Model):
location = models.PointField(blank=True, null=True, srid=4326)
}}}

after:
{{{#!python
class AddressLog(models.Model):
location = models.PointField(blank=True, null=True, srid=3067)
}}}

Migration:
{{{#!python
class Migration(migrations.Migration):

dependencies = [
('myapp', '0002_auto_20171114_1021'),
]

operations = [
migrations.AlterField(
model_name='addresslog',
name='location',
field=django.contrib.gis.db.models.fields.PointField(blank=True,
null=True, srid=3067),
),
]
}}}

Traceback:
{{{#!python
(myapp) jtiai@jns42-l:~/projects/myproject (default) $ ./manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, myapp
Running migrations:
Applying myapp.0003_auto_20171117_0641...Traceback (most recent call
last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/core/management/__init__.py", line 364, in
execute_from_command_line
utility.execute()
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake,
fake_initial=fake_initial)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/db/migrations/executor.py", line 145, in
_migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake,
fake_initial=fake_initial)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/db/migrations/operations/fields.py", line 216, in
database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/jtiai/.virtualenvs/myapp/lib/python3.6/site-
packages/django/db/backends/base/schema.py", line 494, in alter_field
(old_field, new_field),
ValueError: Cannot alter field myapp.AddressLog.location into
myapp.AddressLog.location - they do not properly define db_type (are you
using a badly-written custom field?)
}}}


Using Spatialite as backend engine.

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

Django

unread,
Nov 17, 2017, 5:04:18 AM11/17/17
to django-...@googlegroups.com
#28809: Changing SRID on geometry field doesn't create working migration
--------------------------------+------------------------------------
Reporter: Jani Tiainen | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: migrations gis | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Claude Paroz):

* version: 1.11 => master
* component: Database layer (models, ORM) => GIS
* stage: Unreviewed => Accepted


Comment:

Changing the SRID of a field is something that's hard to do when you have
existing content. I don't think databases are doing anything clever when
you do that (e.g. they don't convert the existing values, AFAIK). Probably
the best strategy is to create a new column, move the values, converting
them in the new SRID in the process, and delete the old column. The
strategy might differ depending on the backend.

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

Django

unread,
Nov 17, 2017, 7:40:12 AM11/17/17
to django-...@googlegroups.com
#28809: Changing SRID on geometry field doesn't create working migration
--------------------------------+------------------------------------
Reporter: Jani Tiainen | Owner: nobody
Type: Bug | Status: new

Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: migrations gis | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------

Comment (by Jani Tiainen):

True, SRID change migrations is not easy to do (might not even be possible
sometimes due missing conversion parameters). But case should be handled
much more gracefully than throwing out traceback.

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

Django

unread,
Nov 17, 2017, 11:58:25 AM11/17/17
to django-...@googlegroups.com
#28809: Changing SRID on geometry field doesn't create working migration
--------------------------------+------------------------------------
Reporter: Jani Tiainen | Owner: nobody
Type: Bug | Status: new

Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: migrations gis | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Sergey Fedoseev):

* cc: Sergey Fedoseev (added)


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

Django

unread,
Nov 18, 2017, 2:41:09 AM11/18/17
to django-...@googlegroups.com
#28809: Changing SRID on geometry field doesn't create working migration
-------------------------------------+-------------------------------------
Reporter: Jani Tiainen | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned

Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: migrations gis | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sergey Fedoseev):

* status: new => assigned
* owner: nobody => Sergey Fedoseev


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

Django

unread,
Feb 18, 2022, 7:17:22 AM2/18/22
to django-...@googlegroups.com
#28809: Changing SRID on geometry field doesn't create working migration
--------------------------------+------------------------------------
Reporter: Jani Tiainen | Owner: (none)
Type: Bug | Status: new
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: migrations gis | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Sergey Fedoseev => (none)
* status: assigned => new


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

Reply all
Reply to author
Forward
0 new messages