[Django] #27933: FieldDoesNotExist if remove foreign key and remove unique constraint at the same time

5 views
Skip to first unread message

Django

unread,
Mar 12, 2017, 11:08:21 AM3/12/17
to django-...@googlegroups.com
#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 | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/27933>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 12, 2017, 11:08:42 AM3/12/17
to django-...@googlegroups.com
#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
-------------------------------+--------------------------------------
Changes (by Jindi Wu):

* Attachment "bug.zip" added.

Django

unread,
Mar 12, 2017, 11:09:29 AM3/12/17
to django-...@googlegroups.com
#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

unread,
Mar 12, 2017, 11:10:51 AM3/12/17
to django-...@googlegroups.com
#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?
>

> Sample app that can reproduce the issue is attached.

New description:

Remove foreign key `b` and `unique_together` 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:2>

Django

unread,
Mar 12, 2017, 2:20:56 PM3/12/17
to django-...@googlegroups.com
#27933: FieldDoesNotExist if remove foreign key and remove unique constraint at the
same time
----------------------------+--------------------------------------

Reporter: Jindi Wu | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* component: Uncategorized => Migrations
* resolution: => duplicate
* type: Uncategorized => Bug


Comment:

Looks like a duplicate of #26180.

--
Ticket URL: <https://code.djangoproject.com/ticket/27933#comment:3>

Reply all
Reply to author
Forward
0 new messages