#26223: Squashing migrations with preserve_default=False keeps the default
--------------------------------+--------------------------------------
Reporter: bartekwojcicki | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by bartekwojcicki):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old 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.
> {{{
> #!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 migrations 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(),
> ),
> ]
> }}}
> }}}
New 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.
{{{
#!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(),
),
]
}}}
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26223#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.28749ef4432bafd982cdc00f43c5286a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.