[Django] #30868: ForeignKey's "to_field" parameter gets the old field's name when renaming a PrimaryKey

16 views
Skip to first unread message

Django

unread,
Oct 10, 2019, 2:06:53 PM10/10/19
to django-...@googlegroups.com
#30868: ForeignKey's "to_field" parameter gets the old field's name when renaming a
PrimaryKey
-------------------------------------+-------------------------------------
Reporter: Carlos E. | Owner: nobody
C. Leite |
Type: Bug | Status: new
Component: | Version: 2.2
Migrations |
Severity: Release | Keywords: migration
blocker | renamefield to_field
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Having these two models

{{{
class ModelA(models.Model):
field_wrong = models.CharField('field1', max_length=50,
primary_key=True) # I'm a Primary key.

}}}

{{{
class ModelB(models.Model):
field_fk = models.ForeignKey(ModelA, blank=True, null=True,
on_delete=models.CASCADE)
}}}

... migrations applyed ...

the `ModelA.field_wrong` field has been renamed ... and Django recognizes
the "renaming"

{{{
# Primary key renamed
class ModelA(models.Model):
field_fixed = models.CharField('field1', max_length=50,
primary_key=True) # I'm a Primary key.

}}}

Attempts to [[span(style=color: #FF0000, to_field)]] parameter.

The **to_field** points to the **old_name** (**field_typo**) and not to
the new one ("**field_fixed**")

{{{
class Migration(migrations.Migration):

dependencies = [
('app1', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='modela',
old_name='field_wrong',
new_name='field_fixed',
),
migrations.AlterField(
model_name='modelb',
name='modela',
field=models.ForeignKey(blank=True, null=True,
on_delete=django.db.models.deletion.CASCADE, to='app1.ModelB',
to_field='field_wrong'),
),
]

}}}

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

Django

unread,
Oct 11, 2019, 5:29:51 AM10/11/19
to django-...@googlegroups.com
#30868: ForeignKey's to_field parameter gets the old field's name when renaming a
PrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Carlos E. C. Leite | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Accepted
renamefield to_field |
Has patch: 0 | Needs documentation: 0

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

* severity: Release blocker => Normal
* cc: Simon Charette (added)
* version: 2.2 => master
* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

Thanks for this ticket. It looks like a regression in
dcdd219ee1e062dc6189f382e0298e0adf5d5ddf, because an `AlterField`
operation wasn't generated in such cases before this change (and I don't
think we need it).

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

Django

unread,
Oct 13, 2019, 9:23:54 PM10/13/19
to django-...@googlegroups.com
#30868: ForeignKey's to_field parameter gets the old field's name when renaming a
PrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Carlos E. C. Leite | Owner: Simon
| Charette
Type: Bug | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Accepted
renamefield to_field |
Has patch: 0 | Needs documentation: 0

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

* owner: nobody => Simon Charette
* status: new => assigned


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

Django

unread,
Oct 13, 2019, 9:57:00 PM10/13/19
to django-...@googlegroups.com
#30868: ForeignKey's to_field parameter gets the old field's name when renaming a
PrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Carlos E. C. Leite | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration | Triage Stage: Accepted
renamefield to_field |
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


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

Django

unread,
Oct 14, 2019, 2:28:40 AM10/14/19
to django-...@googlegroups.com
#30868: ForeignKey's to_field parameter gets the old field's name when renaming a
PrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Carlos E. C. Leite | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: migration | Triage Stage: Accepted
renamefield to_field |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"2839659b42ef80038152768b6cedae1016c59d90" 2839659b]:
{{{
#!CommitTicketReference repository=""
revision="2839659b42ef80038152768b6cedae1016c59d90"
Fixed #30868 -- Prevented unnecessary AlterField when renaming a
referenced pk.

Regression introduced by dcdd219ee1, refs #25817.

Thanks Carlos E. C. Leite for the report and Mariusz for the bisect.
}}}

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

Django

unread,
Oct 14, 2019, 2:28:41 AM10/14/19
to django-...@googlegroups.com
#30868: ForeignKey's to_field parameter gets the old field's name when renaming a
PrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Carlos E. C. Leite | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: migration | Triage Stage: Accepted
renamefield to_field |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"bab3ad54ff30848a16f08d72e70d8edbab019a63" bab3ad5]:
{{{
#!CommitTicketReference repository=""
revision="bab3ad54ff30848a16f08d72e70d8edbab019a63"
[3.0.x] Fixed #30868 -- Prevented unnecessary AlterField when renaming a
referenced pk.

Regression introduced by dcdd219ee1, refs #25817.

Thanks Carlos E. C. Leite for the report and Mariusz for the bisect.

Backport of 2839659b42ef80038152768b6cedae1016c59d90 from master
}}}

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

Django

unread,
Dec 2, 2019, 6:09:07 AM12/2/19
to django-...@googlegroups.com
#30868: ForeignKey's to_field parameter gets the old field's name when renaming a
PrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Carlos E. C. Leite | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: migration | Triage Stage: Accepted
renamefield to_field |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Harro):

Should this be backported to the 2.x branch too?

Seems the same issue is there.

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

Django

unread,
Dec 2, 2019, 6:13:22 AM12/2/19
to django-...@googlegroups.com
#30868: ForeignKey's to_field parameter gets the old field's name when renaming a
PrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Carlos E. C. Leite | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: migration | Triage Stage: Accepted
renamefield to_field |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Unfortunately this patch doesn't qualify for a backport.

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

Reply all
Reply to author
Forward
0 new messages