#26223: Squashing migrations with preserve_default=False keeps the default
--------------------------------+--------------------
     Reporter:  bartekwojcicki  |      Owner:  nobody
         Type:  Bug             |     Status:  new
    Component:  Migrations      |    Version:  1.8
     Severity:  Normal          |   Keywords:
 Triage Stage:  Unreviewed      |  Has patch:  0
Easy pickings:  0               |      UI/UX:  0
--------------------------------+--------------------
 I have a migration with AlterField with default value provided and
 preserve_default=False. When I squash it, I got a CreateModel operation
 with default value for this field set.

 Steps to reproduce:
 1. Create a model, make migrations.
 {{{
 #!div style="font-size: 80%"
   {{{#!python
 class FooBar(models.Model):
     pass
   }}}
 }}}

 2. Add field without default,  make migrations, provide a one-off default.
 {{{
 #!div style="font-size: 80%"
   {{{#!python
 class FooBar(models.Model):
     foo = models.TextField()
   }}}
 }}}

 3. Squash migrations.
 Squashed migrations keeps the default in CreateModel operation.
 {{{
 #!div style="font-size: 80%"
   {{{#!python
     operations = [
         migrations.CreateModel(
             name='FooBar',
             fields=[
                 ('id', models.AutoField(auto_created=True,
 primary_key=True, serialize=False, verbose_name='ID')),
                 ('foo', models.TextField(default='bar')),
             ],
         ),
     ]
   }}}
 }}}

 Running makemigrations again creates a migration with AlterField, removing
 the default
 {{{
 #!div style="font-size: 80%"
   {{{#!python
     operations = [
         migrations.AlterField(
             model_name='foobar',
             name='foo',
             field=models.TextField(),
         ),
     ]
   }}}
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26223>
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/057.3b8a8528e57a5ea8e5e6f0c16ef6f45a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to