Modify ↓
Ticket #996 (closed defect: worksforme)
No foreign keys on manytomany table without through
| Reported by: | hvdklauw@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | blocker | Milestone: | |
| Component: | migrations | Version: | 0.7.3 |
| Keywords: | Cc: | hvdklauw@… |
Description
I just discovered south does not create foreignkey relations on ManyToMany? definitions without through specification.
auth_group_permissions (no south) has ForeignKey? definitions
Every South managed app with a ManyToMany? without a through does not have the foreignkey's defined.
No index, no foreign key is horrible, the django orm generated double negative queries when you try to find elements which only have items on the other side of the relations and thus return less results then then there actually are.
SELECT "producttypes_producttype"."id",
"producttypes_producttype"."title",
"producttypes_producttype"."slug",
"producttypes_producttype"."vat_id",
"producttypes_producttype"."parent_id",
"producttypes_producttype"."slug_url",
"producttypes_producttype"."whole_title",
"producttypes_producttype"."lft",
"producttypes_producttype"."rght",
"producttypes_producttype"."tree_id",
"producttypes_producttype"."level"
FROM "producttypes_producttype"
WHERE NOT (("producttypes_producttype"."id" IN
(SELECT U0."id"
FROM "producttypes_producttype" U0
LEFT OUTER JOIN "products_product_producttypes" U1 ON (U0."id" = U1."producttype_id")
LEFT OUTER JOIN "products_product" U2 ON (U1."product_id" = U2."id")
WHERE (U2."id" IS NULL
AND U0."id" IS NOT NULL))
AND "producttypes_producttype"."id" IS NOT NULL
AND "producttypes_producttype"."id" IS NOT NULL))
ORDER BY "producttypes_producttype"."tree_id" ASC, "producttypes_producttype"."lft" ASC, "producttypes_producttype"."title" ASC
Attachments
Change History
comment:2 Changed 16 months ago by hvdklauw@…
Og I should say this is on PostgreSQL 9 with PostGIS, in case it matters
Note: See
TracTickets for help on using
tickets.

Also see the difference between the ForeignKey? definition for a normal createtable and the one for a M2M table:
('product', models.ForeignKey(orm['products.product'], null=False)),vs
('product', self.gf('django.db.models.fields.related.ForeignKey')(related_name='supplier_orders', to=orm['products.Product'])),