mirror of
https://github.com/django/django.git
synced 2024-12-25 18:46:22 +00:00
Stop errors on older Spatialite versions that miss some tables
This commit is contained in:
parent
746f2a4bed
commit
5f6558f82f
@ -1,3 +1,4 @@
|
|||||||
|
from django.db.utils import DatabaseError
|
||||||
from django.db.backends.sqlite3.schema import DatabaseSchemaEditor
|
from django.db.backends.sqlite3.schema import DatabaseSchemaEditor
|
||||||
|
|
||||||
|
|
||||||
@ -78,12 +79,15 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor):
|
|||||||
self.remove_geometry_metadata(model, field)
|
self.remove_geometry_metadata(model, field)
|
||||||
# Make sure all geom stuff is gone
|
# Make sure all geom stuff is gone
|
||||||
for geom_table in self.geometry_tables:
|
for geom_table in self.geometry_tables:
|
||||||
|
try:
|
||||||
self.execute(
|
self.execute(
|
||||||
self.sql_discard_geometry_columns % {
|
self.sql_discard_geometry_columns % {
|
||||||
"geom_table": geom_table,
|
"geom_table": geom_table,
|
||||||
"table": self.quote_name(model._meta.db_table),
|
"table": self.quote_name(model._meta.db_table),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
except DatabaseError:
|
||||||
|
pass
|
||||||
super(SpatialiteSchemaEditor, self).delete_model(model, **kwargs)
|
super(SpatialiteSchemaEditor, self).delete_model(model, **kwargs)
|
||||||
|
|
||||||
def add_field(self, model, field):
|
def add_field(self, model, field):
|
||||||
@ -112,6 +116,7 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor):
|
|||||||
super(SpatialiteSchemaEditor, self).alter_db_table(model, old_db_table, new_db_table)
|
super(SpatialiteSchemaEditor, self).alter_db_table(model, old_db_table, new_db_table)
|
||||||
# Repoint any straggler names
|
# Repoint any straggler names
|
||||||
for geom_table in self.geometry_tables:
|
for geom_table in self.geometry_tables:
|
||||||
|
try:
|
||||||
self.execute(
|
self.execute(
|
||||||
self.sql_update_geometry_columns % {
|
self.sql_update_geometry_columns % {
|
||||||
"geom_table": geom_table,
|
"geom_table": geom_table,
|
||||||
@ -119,6 +124,8 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor):
|
|||||||
"new_table": self.quote_name(new_db_table),
|
"new_table": self.quote_name(new_db_table),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
except DatabaseError:
|
||||||
|
pass
|
||||||
# Re-add geometry-ness and rename spatial index tables
|
# Re-add geometry-ness and rename spatial index tables
|
||||||
for field in model._meta.local_fields:
|
for field in model._meta.local_fields:
|
||||||
if isinstance(field, GeometryField):
|
if isinstance(field, GeometryField):
|
||||||
|
Loading…
Reference in New Issue
Block a user