[Django] #35176: Renaming a field and its verbose name results in deleting and recreating a new column in django 4.2

6 views
Skip to first unread message

Django

unread,
Feb 8, 2024, 5:49:36 AMFeb 8
to django-...@googlegroups.com
#35176: Renaming a field and its verbose name results in deleting and recreating a
new column in django 4.2
-------------------------------------+-------------------------------------
Reporter: Corentin | Owner: nobody
Bettiol |
Type: Bug | Status: new
Component: | Version: 4.2
Migrations |
Severity: Normal | Keywords: rename, renaming
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35176>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 8, 2024, 5:50:26 AMFeb 8
to django-...@googlegroups.com
#35176: Renaming a field and its verbose name results in deleting and recreating a
new column in django 4.2
----------------------------------+--------------------------------------
Reporter: Corentin Bettiol | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: rename, renaming | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "0001_initial.py" added.

First migration: create the model in db, with 2 fields.

Django

unread,
Feb 8, 2024, 5:51:21 AMFeb 8
to django-...@googlegroups.com
#35176: Renaming a field and its verbose name results in deleting and recreating a
new column in django 4.2
----------------------------------+--------------------------------------
Reporter: Corentin Bettiol | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: rename, renaming | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Corentin Bettiol):

* 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.

Django

unread,
Feb 8, 2024, 5:52:08 AMFeb 8
to django-...@googlegroups.com
#35176: Renaming a field and its verbose name results in deleting and recreating a
new column in django 4.2
----------------------------------+--------------------------------------
Reporter: Corentin Bettiol | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.2
Severity: Normal | Resolution:
Keywords: rename, renaming | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Corentin Bettiol):

* 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.

Reply all
Reply to author
Forward
0 new messages