Opened 9 months ago
Closed 9 months ago
#35176 closed New feature (wontfix)
Renaming a field and other attributes result in deleting and recreating a new column.
Reported by: | Corentin Bettiol | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 4.2 |
Severity: | Normal | Keywords: | rename, renaming |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi all,
When renaming a field of a model in Django, one would expect the makemigration command to realize it should only rename the column in the db.
However, when also renaming the verbose_name, the makemigration command will create a migration file which will delete the column (and all the data it contains), and create a new column.
See the resulting migrations files generated for an example (new project named "a", new app named "b", a simple model containing 2 fields).
I think the makemigration command should handle this case by not deleting data, because we expect it to know that it only needs to rename the column.
Attachments (3)
Change History (5)
by , 9 months ago
Attachment: | 0001_initial.py added |
---|
by , 9 months ago
Attachment: | 0002_rename_a_field_mymodel_a_field_renamed.py added |
---|
Working rename of a field: field "a_field" was renamed "a_field_renamed", using migrations.RenameField.
by , 9 months ago
Attachment: | 0003_remove_mymodel_another_field_and_more.py added |
---|
Nonworking migration: the field "another_field" was deleted, and a new field named "another_field_renamed" was created. Only difference with the previous migration is that the verbose_name of the field also changed.
comment:1 by , 9 months ago
Summary: | Renaming a field and its verbose name results in deleting and recreating a new column in django 4.2 → Renaming a field and its verbose name result in deleting and recreating a new column in django 4.2 |
---|
comment:2 by , 9 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Summary: | Renaming a field and its verbose name result in deleting and recreating a new column in django 4.2 → Renaming a field and other attributes result in deleting and recreating a new column. |
Type: | Bug → New feature |
Migrations are unable to detect that field is renamed after any other attribute changes. You need to do this in two steps:
- rename a field (generate migrations).
- change a verbose name (generate migrations, this is a no-op).
First migration: create the model in db, with 2 fields.