[Django] #24435: Removing blank=True, null=True from ManyToMany field causes data deletion in migration

10 views
Skip to first unread message

Django

unread,
Mar 2, 2015, 7:07:25 AM3/2/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
--------------------------+------------------------------------------------
Reporter: | Owner: nobody
marktranchant |
Type: Bug | Status: new
Component: | Version: 1.7
Migrations |
Severity: Normal | Keywords: m2m migrations deletion blank null
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
--------------------------+------------------------------------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/24435>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 3, 2015, 9:08:15 AM3/3/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8beta1
Severity: Release blocker | Resolution:
Keywords: m2m migrations | Triage Stage: Accepted
deletion blank null |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* severity: Normal => Release blocker
* needs_better_patch: => 0
* needs_tests: => 0
* version: 1.7 => 1.8beta1
* needs_docs: => 0
* stage: Unreviewed => Accepted


Comment:

Seems to be a regression in 1.8 as 1.7 creates a single `AlterField`
operation.

--
Ticket URL: <https://code.djangoproject.com/ticket/24435#comment:1>

Django

unread,
Mar 3, 2015, 6:18:00 PM3/3/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 1.8beta1
Severity: Release blocker | Resolution:
Keywords: m2m migrations | Triage Stage: Accepted
deletion blank null |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* cc: MarkusH (added)


Comment:

Bisected the regression to 623ccdd598625591d1a12fc1564cf3ef9a87581f.
Attaching a regression test.

--
Ticket URL: <https://code.djangoproject.com/ticket/24435#comment:2>

Django

unread,
Mar 4, 2015, 3:36:30 AM3/4/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: MarkusH
Type: Bug | Status: assigned

Component: Migrations | Version: 1.8beta1
Severity: Release blocker | Resolution:
Keywords: m2m migrations | Triage Stage: Accepted
deletion blank null |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by MarkusH):

* status: new => assigned
* owner: nobody => MarkusH


--
Ticket URL: <https://code.djangoproject.com/ticket/24435#comment:3>

Django

unread,
Mar 4, 2015, 3:48:35 AM3/4/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: MarkusH
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8beta1
Severity: Release blocker | Resolution:
Keywords: m2m migrations | Triage Stage: Accepted
deletion blank null |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by MarkusH):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/4233

--
Ticket URL: <https://code.djangoproject.com/ticket/24435#comment:4>

Django

unread,
Mar 4, 2015, 6:50:47 AM3/4/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: MarkusH
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8beta1
Severity: Release blocker | Resolution:
Keywords: m2m migrations | Triage Stage: Ready for
deletion blank null | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/24435#comment:5>

Django

unread,
Mar 4, 2015, 9:41:55 AM3/4/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: 1.8beta1
Severity: Release blocker | Resolution: fixed

Keywords: m2m migrations | Triage Stage: Ready for
deletion blank null | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Markus Holtermann <info@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a9e29fae105d1ddd4e0ac2059cbe62b0ee348bc8"]:
{{{
#!CommitTicketReference repository=""
revision="a9e29fae105d1ddd4e0ac2059cbe62b0ee348bc8"
Fixed #24435 -- Prevented m2m field removal and addition in migrations
when changing blank

Thanks Mark Tranchant for the report an Tim Graham for the test and
review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24435#comment:6>

Django

unread,
Mar 4, 2015, 9:46:44 AM3/4/15
to django-...@googlegroups.com
#24435: Removing blank=True, null=True from ManyToMany field causes data deletion
in migration
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: 1.8beta1
Severity: Release blocker | Resolution: fixed
Keywords: m2m migrations | Triage Stage: Ready for
deletion blank null | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Markus Holtermann <info@…>):

In [changeset:"bff446c205e0c4d436a5147906397ab7534343f3"]:
{{{
#!CommitTicketReference repository=""
revision="bff446c205e0c4d436a5147906397ab7534343f3"
[1.8.x] Fixed #24435 -- Prevented m2m field removal and addition in
migrations when changing blank

Thanks Mark Tranchant for the report and Tim Graham for the test and
review.

Backport of a9e29fae105d1ddd4e0ac2059cbe62b0ee348bc8 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24435#comment:7>

Reply all
Reply to author
Forward
0 new messages