#30868 closed Bug (fixed)
ForeignKey's to_field parameter gets the old field's name when renaming a PrimaryKey.
Reported by: | Carlos Leite | Owned by: | Simon Charette |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | migration renamefield to_field |
Cc: | Simon Charette | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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 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'), ), ]
Change History (7)
comment:1 by , 5 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
Severity: | Release blocker → Normal |
Summary: | ForeignKey's "to_field" parameter gets the old field's name when renaming a PrimaryKey → ForeignKey's to_field parameter gets the old field's name when renaming a PrimaryKey. |
Triage Stage: | Unreviewed → Accepted |
Version: | 2.2 → master |
comment:2 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 5 years ago
Should this be backported to the 2.x branch too?
Seems the same issue is there.
Note:
See TracTickets
for help on using tickets.
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).