#37197 new Uncategorized

GIS fields with Meta.Indexes creates two indexes

Reported by: David Smith Owned by:
Component: GIS Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 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 dryorm.

Geodjango fields should only have one index created when Meta.indexes is used, mirroring the output for non-GIS models?

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top