#29574: Unable to create model instance after changing an abstract model to non-
abstract due to "foreign key mismatch" error
----------------------------+------------------------------------
Reporter: josephbiko | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 2.1
Severity: Normal | 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 Bhuvnesh):
Ok, so i have found the cause (the one above is incorrect):
1. When we run migration for the first time 2 db tables are created (B and
C) , in which {{{C.fk}}} points to primary key of B i.e {{{id}}} .
2. Now when we run second migration, table A is created and B is recreated
with field {{{a_ptr}}} as primary key and all the old fields of B are
deleted(even{{{id}}}). No changes for table C.
3. Since {{{c.fk}}} still points to {{{b.id}}} (at physical level), it
throws {{{foreign_key_mismatch}}} error.
4. If we explicity define primary key in model B everything works as
expected.
{{{
bid = models.IntegerField(primary_key=True)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29574#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/0107018466f4988a-e66e526f-1a06-41a3-bb86-67233469921b-000000%40eu-central-1.amazonses.com.