Modify

Ticket #996 (closed defect: worksforme)

Opened 3 years ago

Last modified 3 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@…

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:1 Changed 3 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)),

vs

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

comment:2 Changed 3 years ago by hvdklauw@…

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

comment:3 Changed 3 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 3 years ago by andrew

  • Status changed from new to closed
  • Resolution set to worksforme
View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.