id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 25614 Changing ForeignKey(on_delete=...) unnecessarily drops and recreates constraints Jeremy Dunck nobody "Recently I changed the on_delete attributes of many ForeignKeys on a MySQL database. This resulted in an auto-detected migration that drops and recreates the constraint for each FK, despite the effective constraint remaining the same (e.g. FOREIGN KEY (`modified_by_id`) REFERENCES `common_user` (`id`); ) The [https://github.com/django/django/blob/1.8.5/django/db/migrations/autodetector.py#L848 autodetection] just compares the deconstruction. The [https://github.com/django/django/blob/1.8.5/django/db/backends/base/schema.py#L486 schema editor] drops the FK and recreates it. It's not entirely clear to me which part needs to be changed - whether the deconstruction should not include on_delete, or whether the autodetector should discard on_delete from consideration, or whether the editor should check for parameters that actually change the effective FK. What is clear is that dropping and recreating FKs isn't a fast operation on large databases, and it would be good to avoid where possible." Bug closed Migrations 1.8 Normal duplicate Unreviewed 0 0 0 0 0 0