#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):
hi, i was working around to find the real cause of this issue and i am
writing my observation here but i am not sure if they are fully correct or
not, it would be really helpful if someone could cross-check/confirm.
1. when {{{a_ptr}}} is created its a primary key hence has UNIQUE
constraint.
2. since {{{a_ptr}}} is a non nullable field it asks for a default value
to populate the existing rows(even for empty db). And as we provide
default value the UNIQUE constraint fails.
3. Now as UNIQUE constraints failed , it defies one of the rule of foreign
key constraints given [https://www.sqlite.org/foreignkeys.html here]
(Under the heading Required and Suggested Database Indexes) which says
{{{The parent key columns named in the foreign key constraint are not the
primary key of the parent table and are not subject to a unique constraint
using collating sequence specified in the CREATE TABLE}}}. This
subsequently leads to the {{{"foreign key mismatch - "models_c"
referencing "models_b""}}} error.
I'm using django dev version and its giving me error as soon as i migrate
second time.
--
Ticket URL: <https://code.djangoproject.com/ticket/29574#comment:8>
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/010701845e59d848-ece15f95-fc16-421f-9299-6caea1d3426c-000000%40eu-central-1.amazonses.com.