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:

  1. Rename field

from

descr = models.TextField('description')

to

description = models.TextField()
  1. 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 Simon Charette, 10 years ago

Cc: Simon Charette added

The rename detection works by comparing removed and added fields and searching for deconstructed args and kwargs equality. It has no notion of name similarity.

In your case, since the field name and its verbose_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 specific args or kwargs 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 and RemoveField with a RenameField operation.

comment:2 by Simon Charette, 10 years ago

Triage Stage: UnreviewedSomeday/Maybe
Type: BugCleanup/optimization

comment:3 by Mariusz Felisiak, 4 years ago

Resolution: duplicate
Status: newclosed
Triage Stage: Someday/MaybeUnreviewed

Duplicate of #32206, which was closed as a duplicate of #31700.

Note: See TracTickets for help on using tickets.
Back to Top