Code

Opened 3 years ago

Closed 11 months ago

#15033 closed Bug (duplicate)

sqlindexes doesn't create indexes for ForeignKeys on normal ManyToManyFields

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

Description

this comment implies that the ForeignKeys created by ManyToManyField tables should also have indexes (makes sense, right? Otherwise we'll have to always create them with custom SQL, or define a through relation every time, gross.)

However sqlindexes doesn't create the indexes. It does create the (from, to) unique constraints, but that's actually not very useful for many queries...

The fix is to change django/core/management/sql.py#L140:

for model in models.get_models(app):

to:

for model in models.get_models(app, include_auto_created=True):

Tested in 1.2.4 and trunk (r15153).

Attachments (0)

Change History (6)

comment:1 Changed 3 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 3 years ago by lukeplant

  • Component changed from Core framework to Database layer (models, ORM)
  • Needs documentation set
  • Triage Stage changed from Ready for checkin to Accepted

I think this needs a documentation change, like the note about the new index here: http://docs.djangoproject.com/en/dev/releases/1.3/#new-index-on-database-session-table

I'm guessing Russell overlooked that, or clicked 'Ready for checkin' instead of 'Accepted', and I'll adjust as I think necessary - apologies to Russell if I've misunderstood something.

comment:3 Changed 3 years ago by anonymous

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 11 months ago by timo

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #15697 (which has a patch)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.