Opened 8 years ago

Last modified 7 weeks ago

#26223 new Bug

Squashing migrations with preserve_default=False keeps the default — at Initial Version

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

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.
    class FooBar(models.Model):
        pass
    
  1. Add field without default, make migrations, provide a one-off default.
    class FooBar(models.Model):
        foo = models.TextField()
    
  1. Squash migrations.

Squashed migrations 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(),
      ),
  ]

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top