[Django] #28493: Foreign keys break on migration if models are renamed in a different app

38 views
Skip to first unread message

Django

unread,
Aug 13, 2017, 2:10:54 PM8/13/17
to django-...@googlegroups.com
#28493: Foreign keys break on migration if models are renamed in a different app
--------------------------------------------------+------------------------
Reporter: Christopher Neugebauer | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
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 |
--------------------------------------------------+------------------------
Steps to reproduce:

1. Create app `a`, with a model called `A`. Run `makemigrations a`
2. Create app `b`, with a model called `B`. Give `B` a `ForeignKey` to
`A`. Run `makemigrations b`
3. Rename model `A` to `Aa`. Run `makemigrations a`
4. Run `migrate`

Expected behaviour:

The migration completes successfully

Actual behaviour:

Migration `0001` on `b` is run after migration `0002` on `a`, and the
migration fails with the following error:

` raise ValueError('Related model %r cannot be resolved' %
self.remote_field.model)
ValueError: Related model u'a.A' cannot be resolved`

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

Django

unread,
Aug 13, 2017, 2:17:29 PM8/13/17
to django-...@googlegroups.com
#28493: Foreign keys break on migration if models are renamed in a different app
-------------------------------------+-------------------------------------
Reporter: Christopher | Owner: nobody
Neugebauer |

Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
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 Christopher Neugebauer:

Old description:

> Steps to reproduce:
>
> 1. Create app `a`, with a model called `A`. Run `makemigrations a`
> 2. Create app `b`, with a model called `B`. Give `B` a `ForeignKey` to
> `A`. Run `makemigrations b`
> 3. Rename model `A` to `Aa`. Run `makemigrations a`
> 4. Run `migrate`
>
> Expected behaviour:
>
> The migration completes successfully
>
> Actual behaviour:
>
> Migration `0001` on `b` is run after migration `0002` on `a`, and the
> migration fails with the following error:
>
> ` raise ValueError('Related model %r cannot be resolved' %
> self.remote_field.model)
> ValueError: Related model u'a.A' cannot be resolved`

New description:

Steps to reproduce:

1. Create app `a`, with a model called `A`. Run `makemigrations a`
2. Create app `b`, with a model called `B`. Give `B` a `ForeignKey` to
`A`. Run `makemigrations b`
3. Rename model `A` to `Aa`. Run `makemigrations a`
4. Run `migrate`

Expected behaviour:

The migration completes successfully

Actual behaviour:

Migration `0001` on `b` is run after migration `0002` on `a`, and the
migration fails with the following error:

{{{
raise ValueError('Related model %r cannot be resolved' %
self.remote_field.model)
ValueError: Related model u'a.A' cannot be resolved
}}}

--

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

Django

unread,
Aug 13, 2017, 2:17:37 PM8/13/17
to django-...@googlegroups.com
#28493: Foreign keys break on migration if models are renamed in a different app
-------------------------------------+-------------------------------------
Reporter: Christopher | Owner: nobody
Neugebauer |
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.11
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 Christopher Neugebauer):

* component: Uncategorized => Migrations


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

Django

unread,
Aug 13, 2017, 2:38:12 PM8/13/17
to django-...@googlegroups.com
#28493: Foreign keys break on migration if models are renamed in a different app
-------------------------------------+-------------------------------------
Reporter: Christopher | Owner: nobody
Neugebauer |
Type: Uncategorized | Status: new

Component: Migrations | Version: 1.11
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
-------------------------------------+-------------------------------------

Comment (by Christopher Neugebauer):

n.b. it is possible to make these migrations work by manually adding
`run_before`, but it seems to me like this *should* be able to run
automatically.

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

Django

unread,
Aug 17, 2017, 5:42:35 PM8/17/17
to django-...@googlegroups.com
#28493: Foreign keys break on migration if models are renamed in a different app
-------------------------------------+-------------------------------------
Reporter: Christopher | Owner: Jeremy
Neugebauer | Satterfield
Type: Uncategorized | Status: assigned

Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jeremy Satterfield):

* owner: nobody => Jeremy Satterfield
* status: new => assigned
* has_patch: 0 => 1


Comment:

This seems to me the exact reason for the dependencies list in migrations.

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

Django

unread,
Aug 21, 2017, 6:04:50 PM8/21/17
to django-...@googlegroups.com
#28493: Foreign keys break on migration if models are renamed in a different app
-------------------------------------+-------------------------------------
Reporter: Christopher | Owner: Jeremy
Neugebauer | Satterfield
Type: Bug | Status: assigned

Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chris Beaven):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Pull request: https://github.com/django/django/pull/8926

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

Django

unread,
Sep 4, 2017, 3:40:16 PM9/4/17
to django-...@googlegroups.com
#28493: Foreign keys break on migration if models are renamed in a different app
-------------------------------------+-------------------------------------
Reporter: Christopher | Owner: Jeremy
Neugebauer | Satterfield
Type: Bug | Status: closed
Component: Migrations | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"0891503fad458e7dfabc5adbf314f80e78e63f14" 0891503f]:
{{{
#!CommitTicketReference repository=""
revision="0891503fad458e7dfabc5adbf314f80e78e63f14"
Fixed #28493 -- Made migrations autodetector find dependencies for model
renaming.
}}}

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

Reply all
Reply to author
Forward
0 new messages