Opened 11 years ago
Closed 5 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 , 11 years ago
| Cc: | added |
|---|
comment:2 by , 11 years ago
| Triage Stage: | Unreviewed → Someday/Maybe |
|---|---|
| Type: | Bug → Cleanup/optimization |
comment:3 by , 5 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
argsandkwargsequality. It has no notion ofnamesimilarity.In your case, since the field
nameand itsverbose_nameare 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
namesimilarity and a whitelist of specificargsorkwargsallowed 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
AddFieldandRemoveFieldwith aRenameFieldoperation.