From 07c79252828c17b9b799d59a3bbbe45c62fe6d38 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Sun, 10 Aug 2014 16:24:19 +0200 Subject: [PATCH] [1.7.x] Fixed remove_field for spatialite schema changes. Backport of f915d39afe3565ac2355de57c11843530b96f3bc from master. --- django/contrib/gis/db/backends/spatialite/schema.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/django/contrib/gis/db/backends/spatialite/schema.py b/django/contrib/gis/db/backends/spatialite/schema.py index 6d3ad3e6b7..18b480d76c 100644 --- a/django/contrib/gis/db/backends/spatialite/schema.py +++ b/django/contrib/gis/db/backends/spatialite/schema.py @@ -101,6 +101,18 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): else: super(SpatialiteSchemaEditor, self).add_field(model, field) + def remove_field(self, model, field): + from django.contrib.gis.db.models.fields import GeometryField + # NOTE: If the field is a geometry field, the table is just recreated, + # the parent's remove_field can't be used cause it will skip the + # recreation if the field does not have a database type. Geometry fields + # do not have a db type cause they are added and removed via stored + # procedures. + if isinstance(field, GeometryField): + self._remake_table(model, delete_fields=[field]) + else: + super(SpatialiteSchemaEditor, self).remove_field(model, field) + def alter_db_table(self, model, old_db_table, new_db_table): from django.contrib.gis.db.models.fields import GeometryField # Remove geometry-ness from temp table