#29854: Altering the primary key targeted by several foreign keys incorrectly
alters the foreign key's NULL attribute on MySQL
-------------------------------------+-------------------------------------
Reporter: Rick Yang | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: MySQL, Migration, | Triage Stage: Accepted
Altering primary key, |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Collin Anderson):
* cc: Collin Anderson (added)
* has_patch: 0 => 1
Comment:
I'm just confirming this is still an issue on mysql and that Baptiste's
"quick workaround" above (sorting the fields) worked for me. I don't know
what the proper solution should be, but it might be worth committing the
workaround.
In my particular case, I'm trying to migrate from an auto-created `id =
AutoField(primary_key=True)` field to `id =
models.CharField(max_length=15, primary_key=True)`, and there's a
`ForeignKey(MyModel, null=True)` that was getting `NOT NULL`, likely
because there are also some `ForeignKey(MyModel, null=False)` fields
referencing this model, and they're getting mixed up.
I think this one's complicated enough that I don't think I'm able to
create a minimal test case, but here's a patch without any tests that
fixes it for me:
https://github.com/django/django/pull/15635
--
Ticket URL: <https://code.djangoproject.com/ticket/29854#comment:9>
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070180672516d3-0abdf1d9-0dc8-4ecd-acfe-ea25164a919b-000000%40eu-central-1.amazonses.com.