Opened 10 years ago

Closed 10 years ago

#8053 closed (fixed)

m2ms with intermediaries break reset

Reported by: Dougal Sutherland Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Using the new intermediaries on many-to-many models breaks the functionality of reset for me.

More specifically, if I create a project "testing" and an application "tests", and put the following models in:

class Band(models.Model):
    name = models.CharField(max_length=100)

class Musician(models.Model):
    name = models.CharField(max_length=100)
    bands = models.ManyToManyField(Band, through='Membership')

class Membership(models.Model):
    band = models.ForeignKey(Band)
    musician = models.ForeignKey(Musician)
    join_date = models.DateField()

after syncdb'ing, if I then try " reset tests", I get an error message. Looking at " sqlclear tests", I get the following output:

DROP TABLE "tests_membership";
DROP TABLE "tests_membership";
DROP TABLE "tests_musician";
DROP TABLE "tests_band";

This duplication comes from, because said function outputs the drop statement for all app models and then for all many-to-many tables. The fix is simple: switch the skip-this-relation condition from checking if the relation is a generic relation to checking the new .creates_table attribute. A patch which does this is attached.

Attachments (1)

patch.diff (532 bytes) - added by Dougal Sutherland 10 years ago.

Download all attachments as: .zip

Change History (2)

Changed 10 years ago by Dougal Sutherland

Attachment: patch.diff added

comment:1 Changed 10 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [8157]) Fixed #8053 -- Corrected a bug with reset and m2m intermediate tables. Thanks to d00gs for the report and fix.

Note: See TracTickets for help on using tickets.
Back to Top