#24435 closed Bug (fixed)
Removing blank=True, null=True from ManyToMany field causes data deletion in migration
Reported by: | Mark Tranchant | Owned by: | Markus Holtermann |
---|---|---|---|
Component: | Migrations | Version: | 1.8beta1 |
Severity: | Release blocker | Keywords: | m2m migrations deletion blank null |
Cc: | Markus Holtermann | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
My app has a Group model with an m2m field in it which used to look like:
things = models.ManyToManyField(Thing, blank=True, null=True)
Django 1.8a1 on my test environment warned me that the blank
and null
arguments were unnecessary, so I removed them:
things = models.ManyToManyField(Thing)
Then I ran manage.py makemigrations
and applied the resulting migration with manage.py migrate
. To my horror, the data in the relevant "linking" table was all deleted.
The section from the migration file looks like this:
operations = [ migrations.RemoveField( model_name='group', name='things', ), migrations.AddField( model_name='group', name='things', field=models.ManyToManyField(to='sa.Thing'), ), ]
This doesn't look like the right behaviour to me, and cost me a lot of time recovering data from backup. Have I done something wrong (other than trusting the migration file without inspecting it) or is this a genuine bug?
Attachments (1)
Change History (8)
comment:1 by , 10 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 1.7 → 1.8beta1 |
comment:2 by , 10 years ago
Cc: | added |
---|
Bisected the regression to 623ccdd598625591d1a12fc1564cf3ef9a87581f. Attaching a regression test.
by , 10 years ago
Attachment: | 24435-test.diff added |
---|
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Seems to be a regression in 1.8 as 1.7 creates a single
AlterField
operation.