From 5f6558f82f980ff1326ae0f71b4cdaa545c6f4c2 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 5 Aug 2014 21:09:37 +1000 Subject: [PATCH] Stop errors on older Spatialite versions that miss some tables --- .../gis/db/backends/spatialite/schema.py | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/django/contrib/gis/db/backends/spatialite/schema.py b/django/contrib/gis/db/backends/spatialite/schema.py index 3271e39a9c..6d3ad3e6b7 100644 --- a/django/contrib/gis/db/backends/spatialite/schema.py +++ b/django/contrib/gis/db/backends/spatialite/schema.py @@ -1,3 +1,4 @@ +from django.db.utils import DatabaseError from django.db.backends.sqlite3.schema import DatabaseSchemaEditor @@ -78,12 +79,15 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): self.remove_geometry_metadata(model, field) # Make sure all geom stuff is gone for geom_table in self.geometry_tables: - self.execute( - self.sql_discard_geometry_columns % { - "geom_table": geom_table, - "table": self.quote_name(model._meta.db_table), - } - ) + try: + self.execute( + self.sql_discard_geometry_columns % { + "geom_table": geom_table, + "table": self.quote_name(model._meta.db_table), + } + ) + except DatabaseError: + pass super(SpatialiteSchemaEditor, self).delete_model(model, **kwargs) def add_field(self, model, field): @@ -112,13 +116,16 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): super(SpatialiteSchemaEditor, self).alter_db_table(model, old_db_table, new_db_table) # Repoint any straggler names for geom_table in self.geometry_tables: - self.execute( - self.sql_update_geometry_columns % { - "geom_table": geom_table, - "old_table": self.quote_name(old_db_table), - "new_table": self.quote_name(new_db_table), - } - ) + try: + self.execute( + self.sql_update_geometry_columns % { + "geom_table": geom_table, + "old_table": self.quote_name(old_db_table), + "new_table": self.quote_name(new_db_table), + } + ) + except DatabaseError: + pass # Re-add geometry-ness and rename spatial index tables for field in model._meta.local_fields: if isinstance(field, GeometryField):