Opened 3 years ago

Last modified 9 months ago

#29058 assigned Bug

Adding 'null=True' to a PointField doesn't create working migration

Reported by: Yaman Ozakin Owned by: Victor Munene
Component: GIS Version: master
Severity: Normal Keywords: geodjango, pointfield
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no



class House(models.Model):
  point = models.PointField()


class House(models.Model):
  point = models.PointField(null=True)


class Migration(migrations.Migration):

    dependencies = [
        ('myapp', '0001_initial'),

    operations = [
            field=django.contrib.gis.db.models.fields.PointField(null=True, srid=4326),


python migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, myapp, sessions
Running migrations:
  Applying myapp.0002_auto_20180125_1119...Traceback (most recent call last):
  File "", line 22, in <module>
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/core/management/", line 364, in execute_from_command_line
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/core/management/", line 356, in execute
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/core/management/", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/core/management/", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/core/management/commands/", line 204, in handle
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/db/migrations/", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/db/migrations/", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/db/migrations/", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/db/migrations/", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/db/migrations/operations/", line 216, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/Users/Basia/yamyam/research/django/myenv/lib/python3.6/site-packages/django/db/backends/base/", line 494, in alter_field
    (old_field, new_field),
ValueError: Cannot alter field myapp.House.point into myapp.House.point - they do not properly define db_type (are you using a badly-written custom field?)

Using Spatialite as backend engine.

Change History (5)

comment:1 Changed 3 years ago by Tim Graham

Component: MigrationsGIS
Triage Stage: UnreviewedAccepted

comment:2 Changed 2 years ago by Jani Tiainen

This is actually more widespread problem with spatialite backend.

DB geometry field in spatialite backend is defined as None which causes any kind of migration, even just adding verbose name which doesn't change field type nor anything database related to cause error message.

All other spatial backends seem to return at least some kind of a db field type.

comment:3 Changed 9 months ago by Victor Munene

Owner: changed from nobody to Victor Munene
Status: newassigned

comment:4 Changed 9 months ago by Victor Munene

Has patch: set

comment:5 Changed 9 months ago by felixxm

Patch needs improvement: set
Version: 1.11master
Note: See TracTickets for help on using tickets.
Back to Top