﻿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
26149	Invalid migration generated when using order_with_respect_to and a unique_together constraint	Richard Xia		"I ran into a bug when trying to generate and apply a migration for a model that has the `order_with_respect_to` option set along with a `unique_together` which involves the implicit `_order` field created by `order_with_respect_to`. For example, if you have the following models:

{{{#!python
class Bar(models.Model):                                                        
    pass                                                                        

class Foo(models.Model):                                                        
    class Meta:                                                                 
        order_with_respect_to = 'bar'                                           
        unique_together = ('bar', '_order')                                     

    bar = models.ForeignKey(Bar)
}}}

when you generate the migrations with `make_migrations`, it creates a migration with the operations out of order. It attempts to run the `AlterUniqueTogether` operation before the `AlterOrderWithRespectTo`, which is problematic because the implicit `_order` field is created by the latter operation but the former operation tries to create a uniqueness constraint using it. This results in the error: `django.core.exceptions.FieldDoesNotExist: Foo has no field named u'_order'`

For convenience, I've created a Github repo that sets up the models, so that to reproduce the bug, all you have to do is run `makemigrations` followed by `migrate`: https://github.com/richardxia/django-migration-bug"	Bug	closed	Migrations	1.9	Normal	fixed			Accepted	1	0	0	1	0	0
