#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.495521ea7f8ee942b86f4ed02815316f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to