Django

Code

Ticket #8053 (closed: fixed)

Opened 4 months ago

Last modified 4 months ago

m2ms with intermediaries break manage.py reset

Reported by: d00gs Assigned to: nobody
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation:
Needs tests: Patch needs improvement:

Description

Using the new intermediaries on many-to-many models breaks the functionality of manage.py 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 "manage.py reset tests", I get an error message. Looking at "manage.py sqlclear tests", I get the following output:

BEGIN;
DROP TABLE "tests_membership";
DROP TABLE "tests_membership";
DROP TABLE "tests_musician";
DROP TABLE "tests_band";
COMMIT;

This duplication comes from django.core.management.sql.sql_delete, 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

patch.diff (0.5 kB) - added by d00gs on 07/31/08 01:20:07.

Change History

07/31/08 01:20:07 changed by d00gs

  • attachment patch.diff added.

07/31/08 02:53:56 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #8053 (m2ms with intermediaries break manage.py reset)




Change Properties
Action