diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-06-18 22:19:11 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-06-20 11:46:33 +0200 |
| commit | adb72fa85423eba238d472a8abfbb65bbc2132d5 (patch) | |
| tree | 319ac489d18edf221aeaf9f4d5774263fd0f9340 /tests | |
| parent | ba81b3f0a35c7753419b4adcf0daca64466c930c (diff) | |
[5.1.x] Refs #35074 -- Avoided failed attempts to remove spatial indexes on nullable fields on MySQL.
MySQL doesn't support spatial indexes on NULL columns, so there is no
point in removing them.
Backport of 20c2d625d3d5062e43918d1d7b6f623202491dd4 from main.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gis_tests/gis_migrations/test_operations.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/gis_tests/gis_migrations/test_operations.py b/tests/gis_tests/gis_migrations/test_operations.py index e81d44caf2..92d542dbb2 100644 --- a/tests/gis_tests/gis_migrations/test_operations.py +++ b/tests/gis_tests/gis_migrations/test_operations.py @@ -134,6 +134,24 @@ class OperationTests(OperationTestCase): if self.has_spatial_indexes: self.assertSpatialIndexExists("gis_neighborhood", "path") + @skipUnless(connection.vendor == "mysql", "MySQL specific test") + def test_remove_geom_field_nullable_with_index(self): + # MySQL doesn't support spatial indexes on NULL columns. + with self.assertNumQueries(1) as ctx: + self.alter_gis_model( + migrations.AddField, + "Neighborhood", + "path", + fields.LineStringField, + field_class_kwargs={"null": True}, + ) + self.assertColumnExists("gis_neighborhood", "path") + self.assertNotIn("CREATE SPATIAL INDEX", ctx.captured_queries[0]["sql"]) + + with self.assertNumQueries(1), self.assertNoLogs("django.contrib.gis", "ERROR"): + self.alter_gis_model(migrations.RemoveField, "Neighborhood", "path") + self.assertColumnNotExists("gis_neighborhood", "path") + @skipUnless(HAS_GEOMETRY_COLUMNS, "Backend doesn't support GeometryColumns.") def test_geom_col_name(self): self.assertEqual( |
