Opened 16 months ago

Closed 8 months ago

Last modified 8 months ago

#22248 closed Bug (fixed)

Model renaming doesn't work backwards

Reported by: andrewgodwin Owned by: andrewgodwin
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: stratoukos, info+coding@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Because of the way ModelRename also triggers AlterField on the foreign keys of other models, it doesn't work in reverse, as that way round the foreign keys are repointed to the old model before it is re-created.

Since some backends (e.g. PostgreSQL) repoint constraints along with renames, we need to make sure that no AlterField is triggered with a rename and then have RenameModel deal with the FKs on MySQL (and perhaps Oracle?)

Change History (13)

comment:1 Changed 16 months ago by andrewgodwin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 16 months ago by andrewgodwin

  • Severity changed from Release blocker to Normal

I'm marking model renames as irreversible for now in order to move this away from release blocker status; there's other irreversible core operations, and we can address this if we get time before the final.

comment:3 Changed 16 months ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 14 months ago by timo

There's a test in tests/migrations/test_operations.py (test_rename_model_with_related) that should be uncommented when this is fixed.

comment:5 Changed 13 months ago by Andrew Godwin <andrew@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 4ce7a6bc84c68406e39f48550434faeef3277eba:

Fixed #22750, #22248: Model renaming now also alters field FKs

comment:6 Changed 13 months ago by Andrew Godwin <andrew@…>

In b568bdf8da30fe5940a31add9f3a2b8029ecb04d:

[1.7.x] Fixed #22750, #22248: Model renaming now also alters field FKs

comment:7 Changed 8 months ago by stratoukos

  • Cc stratoukos added
  • Resolution fixed deleted
  • Status changed from closed to new

Although this seems to be fixed by b568bdf, RenameModel.reversible is still False making RenameModel unreversible.

comment:8 Changed 8 months ago by stratoukos

  • Has patch set
  • Triage Stage changed from Accepted to Unreviewed

I've made a pull request for this: https://github.com/django/django/pull/3572.

comment:9 Changed 8 months ago by charettes

  • Triage Stage changed from Unreviewed to Accepted

The Triage State refers to the ticket and not the patch.

Having Has patch checked with Patch needs improvement unchecked will ensure your patch shows up in the review queue.

comment:10 Changed 8 months ago by stratoukos

Sorry about that, this is my first code contribution to Django. I'll keep it in mind for the future.

comment:11 Changed 8 months ago by MarkusH

  • Cc info+coding@… added
  • Needs documentation set
  • Patch needs improvement set

comment:12 Changed 8 months ago by Stratos Moros <stratos@…>

  • Resolution set to fixed
  • Status changed from new to closed

In cf7a2a000e16b86dd721a021f1a2001529d8d707:

Fixed #22248 -- Made RenameModel reversible

comment:13 Changed 8 months ago by Tim Graham <timograham@…>

In 50434aebe2d3307263ca55f6dd9fa7ace2f87d8f:

[1.7.x] Fixed #22248 -- Made RenameModel reversible

Backport of cf7a2a000e from master

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