#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.7d1f1f154cfef089524ab9b0a7125fc2%40djangoproject.com.