Opened 9 years ago
Last modified 12 months ago
#26223 new Bug
Squashing migrations with preserve_default=False keeps the default — at Version 1
Description (last modified by ) ¶
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:
- Create a model, make migrations.
class FooBar(models.Model): pass
- Add field without default, make migrations, provide a one-off default.
class FooBar(models.Model): foo = models.TextField()
- Squash migrations.
Squashed migration keeps the default in CreateModel operation.
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.
operations = [ migrations.AlterField( model_name='foobar', name='foo', field=models.TextField(), ), ]
According to the ticket's flags, the next step(s) to move this issue forward are:
- To improve the patch as described in the pull request review comments or on this ticket, then uncheck "Patch needs improvement".
If creating a new pull request, include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.