Opened 7 years ago

Last modified 5 years ago

#24067 closed Cleanup/optimization

Renaming Models asks for double confirmation (and doesn't preserve relationships?) — at Initial Version

Reported by: doepunk Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Simon Charette Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When renaming a model (from OldModel to NewModel) I noticed that makemigrations asks for confirmation if I had renamed NewModel to OldModel. Which is great that that was detected and the confirmation helps to get a correct migration file, which makes this step reproducible. The Model in question did not involve any foreign keys to or from it. However when I ran the migrate, I got this message

The following content types are stale and need to be deleted:

    <app-name> | <old-name>

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

I'm unsure what's going on here. But shouldn't renaming involve the automatic deletion of the old name and replacing the foreign keys with the new database table keys? All without a need for confirmation. Or at least if there are no foreign keys as in my case, the confirmation seems unnecessary and it only makes it harder to run the migration unsupervised and it introduces a potential error source. Assuming that all data from the old table were copied to the new table and all foreign key relationships copied and updated as well, I don't see a use case for keeping the old table and "related objects" around. And as for the case that there were any changes in relationships reflected in the Models (other than the name change) this could be detected and confirmed in the makemigrations stage. (For example if there were still references to OldName in the code when OldName no longer exists as a class, this would result in a syntax error, or if a Foreign Key attribute to OldModel was deleted and not replaced with NewModel Foreign Key it's just akin to a field deletion). It just seems more reproducible to keep all confirmations in the makemigration stage.

Change History (0)

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