sqlindexes doesn't output index on manytomany tables although syncdb creates it
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?
Change History
(14)
| Component: |
Uncategorized → Core (Management commands)
|
| milestone: |
→ 1.4
|
| Triage Stage: |
Unreviewed → Accepted
|
| Easy pickings: |
unset
|
| Owner: |
changed from nobody to Ash Christopher
|
| UI/UX: |
unset
|
| Has patch: |
set
|
| Status: |
new → assigned
|
| Needs tests: |
unset
|
| Version: |
1.2
|
| Owner: |
changed from Ash Christopher to Claude Paroz
|
| Version: |
→ master
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
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'> ])