#22035 closed Bug (fixed)

makemigrations when adding field with a unique_together constraint should create fields before constraints

Reported by: SmileyChris Owned by: bak1an
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: antonbaklanov@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Added a slug field to a Tag model, and a unique_together constraint of [('site', 'slug')]

Running makemigrations resulted in a migration with the operations ordered like this:

    operations = [
        migrations.AlterUniqueTogether(
            name='tag',
            unique_together=set([(u'site', u'slug')]),
        ),
        migrations.AddField(
            model_name='tag',
            name='slug',
            field=models.SlugField(default=''),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name='tag',
            name='name',
            field=models.CharField(max_length=20),
        ),
    ]

That choked when running the migration, but manually changing the constraint to happen after the field addition worked fine. Apart from the fact that I should probably have made this two migrations, would it be sensible to order the AlterUniqueTogether operations last?

Change History (3)

comment:1 Changed 17 months ago by bak1an

  • Cc antonbaklanov@… added
  • Needs documentation unset
  • Needs tests unset
  • Owner set to bak1an
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

I can confirm this on current master.
Will try to write test+patch for this now.

comment:2 Changed 17 months ago by bak1an

  • Has patch set
  • Version changed from 1.7-alpha-1 to master

comment:3 Changed 17 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 0bd92d68ade11b56124c7cdfbbfff6eb37899291:

Fixed #22035 -- reordered migration operations

Now AddField actions appear in operations list before AlterUniqueTogether
actions.

Thanks to SmileyChris for the report.

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