Opened 9 months ago

Closed 9 months ago

#35311 closed Bug (duplicate)

Addindex operation generates wrong sql code for Postgresql GinIndex

Reported by: Pierre Juhen Owned by: nobody
Component: Database layer (models, ORM) Version: 5.0
Severity: Normal Keywords: postgresql migration
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)

Hi,

I created a Gin Index using :

GinIndex(OpClass(Lower('title'),      name='gin_trgm_ops'), name="name_gin_trgm_title_affaire"),'

makemigrations generates the following code :

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

SQLMIGRATE generates a wrong code :

CREATE INDEX "name_gin_trgm_title_affaire" ON "affaires_affaire" USING gin ((LOWER("title"), name=gin_trgm_ops));''

Instead of (too many parenthesis) :

CREATE INDEX "name_gin_trgm_title_affaire" ON "affaires_affaire" USING gin (LOWER("title"),  name=gin_trgm_ops);''

There is a manual workaround, but its annoying.

Thank you.

Regards

Change History (2)

comment:1 by Pierre Juhen, 9 months ago

Description: modified (diff)

comment:2 by Tim Graham, 9 months ago

Description: modified (diff)
Resolution: duplicate
Status: newclosed

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