Opened 6 years ago

Closed 3 years ago

#15697 closed Bug (fixed)

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

Reported by: Markus Bertheau Owned by: Claude Paroz
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 Ash Christopher 5 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 5 years ago by Luke Plant

Type: Bug

comment:2 Changed 5 years ago by Luke Plant

Severity: Normal

comment:3 Changed 5 years ago by Jacob

Component: UncategorizedCore (Management commands)
milestone: 1.4
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:4 Changed 5 years ago by Ash Christopher

Easy pickings: unset
Owner: changed from nobody to Ash Christopher
UI/UX: unset

comment:5 Changed 5 years ago by Ash Christopher

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.

set([
    <class 'django.contrib.auth.models.Group_permissions'>, <class 'django.contrib.auth.models.User'>, 
    <class 'django.contrib.sites.models.Site'>, 
    <class 'django.contrib.auth.models.User_user_permissions'>, 
    <class 'myapp.models.B_a'>, 
    <class 'django.contrib.auth.models.Group'>, 
    <class 'myapp.models.B'>, 
    <class 'django.contrib.auth.models.Permission'>, 
    <class 'myapp.models.A'>, 
    <class 'django.contrib.sessions.models.Session'>, 
    <class 'django.contrib.contenttypes.models.ContentType'>, 
    <class 'django.contrib.auth.models.User_groups'>
])
Last edited 5 years ago by Ash Christopher (previous) (diff)

Changed 5 years ago by Ash Christopher

Attachment: ticket15697.diff added

comment:6 Changed 5 years ago by Ash Christopher

Has patch: set
Status: newassigned

comment:7 Changed 5 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

comment:8 Changed 5 years ago by Ash Christopher

Easy pickings: set

comment:9 Changed 5 years ago by Claude Paroz

Needs tests: set

comment:10 Changed 4 years ago by Ash Christopher

Currently porting patch and adding tests.

comment:11 Changed 4 years ago by Ash Christopher

Needs tests: unset
Version: 1.2

comment:12 Changed 3 years ago by Claude Paroz

Owner: changed from Ash Christopher to Claude Paroz
Version: master

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

Resolution: fixed
Status: assignedclosed

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