[Django] #37197: GIS fields with Meta.Indexes creates two indexes

4 views
Skip to first unread message

Django

unread,
Jun 29, 2026, 3:43:30 PM (yesterday) Jun 29
to django-...@googlegroups.com
#37197: GIS fields with Meta.Indexes creates two indexes
-----------------------------+-----------------------------------------
Reporter: David Smith | Type: Uncategorized
Status: new | Component: GIS
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-----------------------------------------
Given this model

{{{
from django.contrib.gis.db import models

class City(models.Model):
point = models.PointField()

class Meta:
indexes = [models.Index(fields=['point'], name='another_index')]
}}}

The output of `sqlmigrate` is the following - notice the two `CREATE
INDEX` statements:

{{{
CREATE TABLE "ticket_31252_city" ("id" bigint NOT NULL PRIMARY KEY
GENERATED BY DEFAULT AS IDENTITY, "point" geometry(POINT,4326) NOT NULL);
CREATE INDEX "ticket_31252_city_point_41eaedb4_id" ON "ticket_31252_city"
USING GIST ("point");
CREATE INDEX "another_index" ON "ticket_31252_city" USING GIST ("point");
}}}

Re-created on [https://dryorm.xterm.info/gis-double-index dryorm].

Compare this to a non-GIS model:

{{{
from django.db import models

class City(models.Model):
point = models.CharField(max_length=100)

class Meta:
indexes = [models.Index(fields=['point'], name='another_index')]
}}}

Only a single index is created - see
[https://dryorm.xterm.info/single_index dryorm].

Geodjango fields should only have one index created when Meta.indexes is
used, mirroring the output for non-GIS models?
--
Ticket URL: <https://code.djangoproject.com/ticket/37197>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 29, 2026, 5:09:24 PM (yesterday) Jun 29
to django-...@googlegroups.com
#37197: GIS fields with Meta.Indexes creates two indexes
-------------------------------+--------------------------------------
Reporter: David Smith | Owner: (none)
Type: Uncategorized | Status: closed
Component: GIS | Version: 6.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by David Smith):

* resolution: => invalid
* status: new => closed

Comment:

This is because an index is added by default for spatial fields. You'd set
`spatial_index=False` on the field if you wanted to set it in
`Meta.Indexes` instead.
--
Ticket URL: <https://code.djangoproject.com/ticket/37197#comment:1>
Reply all
Reply to author
Forward
0 new messages