Opened 4 years ago

Closed 2 years ago

#15697 closed Bug (fixed)

sqlindexes doesn't output index on manytomany tables although syncdb creates it

Reported by: mbertheau Owned by: claudep
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Django 1.2.5, Ubuntu 10.10.

With these simple models:

class A(models.Model):
    pass

class B(models.Model):
    a = models.ManyToManyField(A)

./manage.py sqlindexes myapp doesn't output the following CREATE INDEX statement, but ./manage.py syncdb does create them:

CREATE INDEX `myapp_b_a_3797486b` ON `myapp_b_a` (`b_id`);
CREATE INDEX `myapp_b_a_776cf5a8` ON `myapp_b_a` (`a_id`);

Shouldn’t the output of ./manage.py sqlindexes correspond to what ./manage.py syncdb does?

Attachments (1)

ticket15697.diff (712 bytes) - added by ashchristopher 4 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 4 years ago by lukeplant

  • Type set to Bug

comment:2 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:3 Changed 4 years ago by jacob

  • Component changed from Uncategorized to Core (Management commands)
  • milestone set to 1.4
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 4 years ago by ashchristopher

  • Easy pickings unset
  • Owner changed from nobody to ashchristopher
  • UI/UX unset

comment:5 Changed 4 years ago by ashchristopher

Took a look at the code:

In syncdb, there are our defined models and there are also models to represent the intermediate tables.

If we use the above example, we define A and B models but when we run syncdb, there is an intermediate model generated called B_a which actually contains the indexes.

When you call sqlindexes, or sql, or sqlall we only ever reference the models defined in our models.py and we don't actually reference the intermediate model.

Version 0, edited 4 years ago by ashchristopher (next)

Changed 4 years ago by ashchristopher

comment:6 Changed 4 years ago by ashchristopher

  • Has patch set
  • Status changed from new to assigned

comment:7 Changed 4 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:8 Changed 4 years ago by ashchristopher

  • Easy pickings set

comment:9 Changed 4 years ago by claudep

  • Needs tests set

comment:10 Changed 3 years ago by ashchristopher

Currently porting patch and adding tests.

comment:11 Changed 3 years ago by ashchristopher

  • Needs tests unset
  • Version 1.2 deleted

comment:12 Changed 2 years ago by claudep

  • Owner changed from ashchristopher to claudep
  • Version set to master

comment:13 Changed 2 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 8010289ea2f30f0bb819feba7ec78e67c198023b:

Fixed #15697 -- Made sqlindexes aware of auto-created tables

Thanks mbertheau for the report and Ash Christopher for the
initial patch.

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