Opened 12 years ago
Closed 12 years ago
#22035 closed Bug (fixed)
makemigrations when adding field with a unique_together constraint should create fields before constraints
| Reported by: | Chris Beaven | Owned by: | Anton Baklanov |
|---|---|---|---|
| Component: | Migrations | Version: | dev |
| 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 by , 12 years ago
| Cc: | added |
|---|---|
| Owner: | set to |
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
I can confirm this on current master.
Will try to write test+patch for this now.