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 Bartek Wójcicki)

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

Change History (1)

comment:1 by Bartek Wójcicki, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top