#27933: FieldDoesNotExist if remove foreign key and remove unique constraint at 
the
same time
-------------------------------+--------------------------------------
     Reporter:  Jindi Wu       |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Uncategorized  |                  Version:  1.10
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Description changed by Jindi Wu:

Old description:

> Remove foreign key b and unique_togetehr constraint from model like
> following:
> {{{
> class A(models.Model):
>     name = models.CharField(max_length=10)
>     b = models.ForeignKey('B')
>
>     class Meta:
>         unique_together = (('b','name'),)
>
> class B(models.Model):
>     text = models.CharField(max_length=10)
> }}}
>
> -->
>
> {{{
> class A(models.Model):
>     name = models.CharField(max_length=10)
>
>     class Meta:
>         unique_together = (('name'),)
>
> class B(models.Model):
>     text = models.CharField(max_length=10)
> }}}
>
> Such error will be thrown.
>
> {{{
> raise FieldDoesNotExist('%s has no field named %r' % (self.object_name,
> field_name))
> django.core.exceptions.FieldDoesNotExist: A has no field named 'b'
> }}}
>
> However if swap the order of generated two operations within the
> migration AlterUniqueTogether and RemoveField, it'll work.
>
> Is this a bug or am I using Django the wrong way?

New description:

 Remove foreign key b and unique_togetehr constraint from model like
 following:
 {{{
 class A(models.Model):
     name = models.CharField(max_length=10)
     b = models.ForeignKey('B')

     class Meta:
         unique_together = (('b','name'),)

 class B(models.Model):
     text = models.CharField(max_length=10)
 }}}

 -->

 {{{
 class A(models.Model):
     name = models.CharField(max_length=10)

     class Meta:
         unique_together = (('name'),)

 class B(models.Model):
     text = models.CharField(max_length=10)
 }}}

 Such error will be thrown.

 {{{
 raise FieldDoesNotExist('%s has no field named %r' % (self.object_name,
 field_name))
 django.core.exceptions.FieldDoesNotExist: A has no field named 'b'
 }}}

 However if swap the order of generated two operations within the migration
 AlterUniqueTogether and RemoveField, it'll work.

 Is this a bug or am I using Django the wrong way?

 Sample app that can reproduce the issue is attached.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27933#comment:1>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.594a93f63741bff86e7567d35272ff44%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to