Opened 10 years ago
Closed 4 years ago
#24157 closed Cleanup/optimization (duplicate)
Prompt to add a new field after renaming
Reported by: | Basil Upornikov | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Simon Charette | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have noticed a slightly weird logic of makemigration command after renaming a field in a model.py.
So, I did this:
- Rename field
from
descr = models.TextField('description')
to
description = models.TextField()
- Invoke
manage.py makemigrations
And migration logic decided that I had added a new field description and asked me to provide default value.
But if to perform renaming this way:
from
descr = models.TextField('description')
to
description = models.TextField('description') # note a passed verbose name argument
then migration logic works well and recognizes renaming.
Change History (3)
comment:1 by , 10 years ago
Cc: | added |
---|
comment:2 by , 10 years ago
Triage Stage: | Unreviewed → Someday/Maybe |
---|---|
Type: | Bug → Cleanup/optimization |
comment:3 by , 4 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Triage Stage: | Someday/Maybe → Unreviewed |
Note:
See TracTickets
for help on using tickets.
The rename detection works by comparing removed and added fields and searching for deconstructed
args
andkwargs
equality. It has no notion ofname
similarity.In your case, since the field
name
and itsverbose_name
are changed at the same time the autodetector fails to prompt you for a possible rename.I'm afraid this cannot be solved easily without some kind of heuristics to detect
name
similarity and a whitelist of specificargs
orkwargs
allowed to be changed during a rename.I think we should close this ticket as Wont Fix or document the limitations of the actual implementation. Users are still allowed to manually replace the generated
AddField
andRemoveField
with aRenameField
operation.