Opened 22 months ago

Last modified 22 months ago

#28053 new New feature

Allow fields to specify arbitrary indexes via db_index=Index()

Reported by: Marc Tamlyn Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords: indexes migrations
Cc: Markus Holtermann Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no


Expand Field.db_index to allow explicitly setting an index.

Syntax would look something like:


Changes needed:

  • Indexes won't necessarily receive fields initially.
  • Fields are responsible for their own indexes. This is tackled here and has implications for #27859, _like indexes on Postgres, and other situations where we customise the indexes. It is possible, but I'm not sure, that Field.get_indexes() could also handle unique conditions, but I think it's better kept separately as not all databases consider uniqueness to be an index.
  • Change to SchemaEditor.alter_field so it receives the to_model, so that the Index can resolve the correct column names. This is extra important for db_index being a functional index (see #26167), although that's not currently supported in the current data.

Change History (2)

comment:1 Changed 22 months ago by Markus Holtermann

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 22 months ago by Tim Graham

Type: UncategorizedNew feature


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