﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30868	ForeignKey's to_field parameter gets the old field's name when renaming a PrimaryKey.	Carlos Leite	Simon Charette	"
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'),
        ),
    ]

}}}

"	Bug	closed	Migrations	dev	Normal	fixed	migration renamefield to_field	Simon Charette	Accepted	1	0	0	0	0	0
