Opened 9 years ago

Closed 9 years ago

#25214 closed Bug (needsinfo)

Behavior of _meta.auto_created = True in m2m through model is not expected.

Reported by: Chaoyi Du Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have models like:

class A(models.Model):
    ...
    b = models.ManyToManyField(
        'B',
        through='Through',
    )
   ...

class B(models.Model):
   ...

class Through(models.Model):
    a = models.ForeignKey('A')
    b = models.ForeignKey('B')
    ...
    # other fields have default value

    class Meta:
        auto_created = False

If I make migrations at this point, joint table 'Through' will be created.

Then if I set "Through._meta.auto_created = True" somewhere, and never update migrations. Everything works well. If I add a new relationship between A instance and B instance, a through object will be created with default value, which looks great.

However if I update migrations, the "Through" model will be removed in migrations and everything break.

I think a through model with auto_created=True should be kept in migrations and when new relationships created, through objects shall be created with claimed default value.

Change History (2)

comment:1 by Tim Graham, 9 years ago

Could you be a bit more explicit with the steps involved to reproduce the issue? e.g. "Here are my initial models... Then I make this change and run this command... etc."

comment:2 by Tim Graham, 9 years ago

Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top