diff --git a/django/contrib/gis/db/backends/spatialite/schema.py b/django/contrib/gis/db/backends/spatialite/schema.py index d37632edf87..d75d7671e53 100644 --- a/django/contrib/gis/db/backends/spatialite/schema.py +++ b/django/contrib/gis/db/backends/spatialite/schema.py @@ -139,6 +139,11 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): ): from django.contrib.gis.db.models import GeometryField + if old_db_table == new_db_table or ( + self.connection.features.ignores_table_name_case + and old_db_table.lower() == new_db_table.lower() + ): + return # Remove geometry-ness from temp table for field in model._meta.local_fields: if isinstance(field, GeometryField): diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index e377e4ca640..a8fcb057ce2 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -988,6 +988,15 @@ class OperationTests(OperationTestBase): "test_rmwsc_rider", ["pony_id"], ("test_rmwsc_littlehorse", "id") ) + def test_rename_model_no_relations_with_db_table_noop(self): + app_label = "test_rmwdbtnoop" + project_state = self.set_up_test_model(app_label, db_table="my_pony") + operation = migrations.RenameModel("Pony", "LittleHorse") + new_state = project_state.clone() + operation.state_forwards(app_label, new_state) + with connection.schema_editor() as editor, self.assertNumQueries(0): + operation.database_forwards(app_label, editor, project_state, new_state) + def test_rename_model_with_self_referential_m2m(self): app_label = "test_rename_model_with_self_referential_m2m"