[Django] #23794: FieldDoesNotExist error in migration with deleted fields and unique_together constraint

33 views
Skip to first unread message

Django

unread,
Nov 10, 2014, 9:56:45 PM11/10/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
heybuddy | Status: new
Type: | Version: 1.7
Uncategorized | Keywords: migration unique_together
Component: | removefield
Migrations | Has patch: 0
Severity: Normal | UI/UX: 0
Triage Stage: |
Unreviewed |
Easy pickings: 0 |
-------------------------+-------------------------------------------------
I had a model that had a ForeignKey field and a unique_together constraint
involving that field. I deleted both the field and the unique_together
constraint in my model and ran makemigrations. The migration created
RemoveField operation and a AlterUniqueTogether operation with
unique_together=set([]). When I tried to run the migration, a
django.db.models.fields.FieldDoesNotExist exception occured. I edited the
migration manually to put the AlterUniqueTogether operation before the
RemoveField operation and then the migration worked.

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

Django

unread,
Nov 10, 2014, 11:09:38 PM11/10/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Accepted
unique_together removefield | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by charettes):

* needs_better_patch: => 0
* needs_tests: => 0
* version: 1.7 => master
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Managed to reproduce against master.

--
Ticket URL: <https://code.djangoproject.com/ticket/23794#comment:1>

Django

unread,
Nov 15, 2014, 5:53:20 AM11/15/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: trg
Type: Bug | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Accepted
unique_together removefield | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by trg):

* owner: nobody => trg
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/23794#comment:2>

Django

unread,
Nov 15, 2014, 10:05:00 AM11/15/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: trg
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: migration | Triage Stage: Accepted
unique_together removefield | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by trg):

* status: assigned => closed
* resolution: => fixed


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

Django

unread,
Nov 15, 2014, 10:11:17 AM11/15/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: trg
Type: Bug | Status: new

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Accepted
unique_together removefield | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0

Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by charettes):

* status: closed => new
* has_patch: 0 => 1
* resolution: fixed =>


Comment:

Pull-request submitted at https://github.com/django/django/pull/3533

--
Ticket URL: <https://code.djangoproject.com/ticket/23794#comment:4>

Django

unread,
Nov 16, 2014, 7:46:07 PM11/16/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: trg
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Accepted
unique_together removefield | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by MarkusH):

* cc: info+coding@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/23794#comment:5>

Django

unread,
Nov 21, 2014, 10:57:25 AM11/21/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: trg
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: migration | Triage Stage: Accepted
unique_together removefield | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"72729f844e0dd9bd01b3874171b89ab0d136a40e"]:
{{{
#!CommitTicketReference repository=""
revision="72729f844e0dd9bd01b3874171b89ab0d136a40e"
Fixed #23794 -- Fixed migrations crash when removing a field that's part
of index/unique_together.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23794#comment:6>

Django

unread,
Nov 21, 2014, 10:57:49 AM11/21/14
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: trg
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: migration | Triage Stage: Accepted
unique_together removefield | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"feded19104b14bc28aaccf550265157df84593ba"]:
{{{
#!CommitTicketReference repository=""
revision="feded19104b14bc28aaccf550265157df84593ba"
[1.7.x] Fixed #23794 -- Fixed migrations crash when removing a field


that's part of index/unique_together.

Backport of 72729f844e0dd9bd01b3874171b89ab0d136a40e from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23794#comment:7>

Django

unread,
Sep 11, 2015, 12:50:32 PM9/11/15
to django-...@googlegroups.com
#23794: FieldDoesNotExist error in migration with deleted fields and
unique_together constraint
-------------------------------------+-------------------------------------
Reporter: heybuddy | Owner: trg
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: migration | Triage Stage: Accepted
unique_together removefield |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by berto:

Old description:

> I had a model that had a ForeignKey field and a unique_together
> constraint involving that field. I deleted both the field and the
> unique_together constraint in my model and ran makemigrations. The
> migration created RemoveField operation and a AlterUniqueTogether
> operation with unique_together=set([]). When I tried to run the
> migration, a django.db.models.fields.FieldDoesNotExist exception occured.
> I edited the migration manually to put the AlterUniqueTogether operation
> before the RemoveField operation and then the migration worked.

New description:

I had a model that had a ForeignKey field and a unique_together constraint
involving that field. I deleted both the field and the unique_together
constraint in my model and ran makemigrations. The migration created
RemoveField operation and a AlterUniqueTogether operation with
unique_together=set([]). When I tried to run the migration, a
django.db.models.fields.FieldDoesNotExist exception occured. I edited the
migration manually to put the AlterUniqueTogether operation before the
RemoveField operation and then the migration worked.

NOTE: After upgrading, you must remove the bad migration file and re-run
`makemigrations` or manually move the `AlterUniqueTogether` operation
manually as stated above; i.e. upgrading does not fix the existing
migration.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/23794#comment:8>

Reply all
Reply to author
Forward
0 new messages