﻿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
34333	Django migrations adds constraint before adding field	Raphael Beekmann	nobody	"Hello,

I have a model, already created through previous migrations, and in a new migration I added a new field with a UniqueConstraint.
The model looks like this (the new field is 'type') : 


{{{
class Model(models.Model):
    name = models.CharField()
    date = models.DateField()
    type = models.ForeignKey(OtherModel)

    class Meta:
        constraints = (
            models.UniqueConstraint(fields=('date', 'type'), name='unique_date_for_type'),
        )
}}}

When I run the makemigrations script it adds first the constraint and then the new field. That occurs an error when executing the migration : 

{{{
django.core.exceptions.FieldDoesNotExist: DailyTask has no field named 'type'
}}}

I have to manually move the adds of the constraint before the adds of the new field in the migration file to make it work.

"	Bug	new	Migrations	4.1	Normal		migration, constraint, field		Unreviewed	0	0	0	0	0	0
