#26149: Invalid migration generated when using order_with_respect_to and a
unique_together constraint
----------------------------+--------------------
     Reporter:  richardxia  |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  1.9
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 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

--
Ticket URL: <https://code.djangoproject.com/ticket/26149>
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/053.6c9f809336e9bc3533d1a439a5149a73%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to