#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Mário Falcão):
* needs_better_patch: 1 => 0
Old description:
> Changing `spatial_index` on existing spatial fields causes migrations to
> be generated as expected, but they do not actually drop/create the
> indexes as desired when applied (`manage.py sqlmigrate` reports them as
> no-ops).
>
> Detected on Django 4.2.8 with PostGIS, but also present on latest main
> branch.
New description:
Changing `spatial_index` on existing spatial fields causes migrations to
be generated as expected, but they do not actually drop/create the indexes
as desired when applied.
E.g. starting with the following model
{{{
class LocationUpdate(models.Model):
location = PointField(geography=True, spatial_index=False)
}}}
If we change `spatial_index` to `True`, a migration is generated with a
single operation:
{{{
migrations.AlterField(
model_name="locationupdate",
name="location",
field=django.contrib.gis.db.models.fields.PointField(
geography=True, srid=4326
),
)
}}}
But applying this migration does not create the expected index and the
output of `sqlmigrate` is as follows:
{{{
BEGIN;
--
-- Alter field location on locationupdate
--
-- (no-op)
COMMIT;
}}}
Detected on Django 4.2.8 with PostGIS, but also present on latest main
branch across all backends.
--
Comment:
Turns out that none of the GIS backends handled this and I believe they
never did.
My patch is now ready for review - it should fix this on PostGIS, MySQL
and Oracle. Spatialite is not implemented as it does not support altering
geo fields.
--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018cbdb68b9c-d3be2e5c-98d8-4263-a2a8-23649f8026b5-000000%40eu-central-1.amazonses.com.