﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26223	Squashing migrations with preserve_default=False keeps the default	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.
{{{
#!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 migration 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(),
        ),
    ]
  }}}
}}}"	Bug	new	Migrations	dev	Normal			Markus Holtermann InvalidInterrupt Ülgen Sarıkavak Roman Donchenko	Accepted	1	0	0	1	0	0
