Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#35262 closed Bug (duplicate)

Addindex operation generates wrong sql code for Postgresql GinIndex

Reported by: Pierre Juhen Owned by: nobody
Component: contrib.postgres Version: 5.0
Severity: Normal Keywords:
Cc: Pierre Juhen Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

I have created a Gin Index using the folowing code in models.py

GinIndex(OpClass(Lower('historique'), name='gin_trgm_ops'), name="name_gin_trgm_histo_affaire")

It generates a migration operation :

migrations.AddIndex(
    model_name='affaire',
    index=django.contrib.postgres.indexes.GinIndex(django.contrib.postgres.indexes.OpClass(django.db.models.functions.text.Lower('historique'), name='gin_trgm_ops'), name='name_gin_trgm_histo_affaire'),
)

The SQL generated instruction is :

CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING gin ((LOWER("historique") gin_trgm_ops));

It is refused by postgresql.

The right code might be :

CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING gin (LOWER("historique") );

that accepted by postgresql.

Change History (3)

comment:1 by Tim Graham, 7 months ago

Component: Uncategorizedcontrib.postgres
Description: modified (diff)

comment:2 by Mariusz Felisiak, 7 months ago

Resolution: worksforme
Status: newclosed

It works for me and is covered in our test suite.

comment:3 by Tim Graham, 7 months ago

Resolution: worksformeduplicate

Duplicate of #33021. django.contrib.postgres must be in INSTALLED_APPS when using OpClass(). See docs and related ticket #32770.

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