Opened 9 years ago
Last modified 8 months ago
#26223 new Bug
Squashing migrations with preserve_default=False keeps the default — at Version 1
Reported by: | Bartek Wójcicki | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Markus Holtermann, InvalidInterrupt, Ülgen Sarıkavak | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
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(), ), ]
Note:
See TracTickets
for help on using tickets.