Opened 8 years ago

Closed 8 years ago

#27933 closed Bug (duplicate)

FieldDoesNotExist if remove foreign key and remove unique constraint at the same time

Reported by: Jindi Wu Owned by: nobody
Component: Migrations Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jindi Wu)

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.

Attachments (1)

bug.zip (18.3 KB ) - added by Jindi Wu 8 years ago.

Download all attachments as: .zip

Change History (4)

by Jindi Wu, 8 years ago

Attachment: bug.zip added

comment:1 by Jindi Wu, 8 years ago

Description: modified (diff)

comment:2 by Jindi Wu, 8 years ago

Description: modified (diff)

comment:3 by Tim Graham, 8 years ago

Component: UncategorizedMigrations
Resolution: duplicate
Status: newclosed
Type: UncategorizedBug

Looks like a duplicate of #26180.

Note: See TracTickets for help on using tickets.
Back to Top