Ticket #996 (closed defect: worksforme)

Opened 4 years ago

Last modified 4 years ago

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@…


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",
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

Change History

comment:1 Changed 4 years ago by hvdklauw@…

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)),


('product', self.gf('django.db.models.fields.related.ForeignKey')(related_name='supplier_orders', to=orm['products.Product'])),

comment:2 Changed 4 years ago by hvdklauw@…

Og I should say this is on PostgreSQL 9 with PostGIS, in case it matters

comment:3 Changed 4 years ago by hvdklauw@…

After more investigation it seems it was this particular project which had this issue only.
Strangly all m2m without through tables are affected.

As I can't reproduct this with a clean project I'd say close this ticket.

comment:4 Changed 4 years ago by andrew

  • Status changed from new to closed
  • Resolution set to worksforme
Note: See TracTickets for help on using tickets.