#29193: Altering a field with a unique constraint drops and rebuilds FKs to other fields in the table ---------------------------------+------------------------------------ Reporter: Jeremy Bowman | Owner: nobody Type: Bug | Status: new Component: Migrations | Version: 1.11 Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+------------------------------------
Comment (by Joshua Massover): https://github.com/massover/bug_29193 The above is a small project to reproduce. I could not reproduce it with the built in auth User model. I used a custom User model. While using the built in auth User model, it looked `_related_non_m2m_objects` did not return my related models because of `related_objects`. It looks like the code that changed the behavior is this https://github.com/django/django/commit/c3e0adcad8d8ba94b33cabd137056166ed36dae0 #diff-b69190ab88f6c5737b2562d94d7bf36bR539 {{{ # Drop incoming FK constraints if the field is a primary key or unique, # which might be a to_field target, and things are going to change. drop_foreign_keys = ( ( (old_field.primary_key and new_field.primary_key) (old_field.unique and new_field.unique) ) and old_type != new_type ) }}} Before it would only drop and recreate constraints if the field was a foreign key. Now it drops and recreates all constraints if the field is unique. Naively removing the unique check that was added in https://code.djangoproject.com/ticket/28305 will fix this problem. All the tests pass. Looking back at the ticket I don't really understand the intention, so this seems like an awful idea. -- Ticket URL: <https://code.djangoproject.com/ticket/29193#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.709b78a3366899aee18d6ec66b72acc5%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.