#30513: Impossible migration (with a change of model base) is not noticed
-----------------------------------------+------------------------
Reporter: Victor Porton | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
1. Extract the attached Git repository. (It contains among other
migrations automatically created with `makemigrations`, one of the
migrations was made with choosing the option `2) Ignore for now, and let
me handle existing rows with NULL myself (e.g. because you added a
RunPython or RunSQL operation to handle NULL values in a previous data
migration)`.)
2. Try to migrate.
You see the error:
{{{
django.db.utils.OperationalError: foreign key mismatch - "mytest_project"
referencing "mytest_token"
}}}
The Django bug is that this error is noticed too late: on the stage of
`migrate` not where it should have been noticed, the stage of
`makemigrations`.
The bug appears when I try to replace (in two stages as described by tags
below, because Django does not allow to do it in one stage):
{{{
class Token(models.Model):
pass
}}}
with
{{{
class BaseToken(models.Model):
pass
class Token(BaseToken):
base = models.OneToOneField(BaseToken, on_delete=models.CASCADE,
primary_key=True)
}}}
This happens because this change unnoticed by Django replaces what is used
as the primary key for `Token`.
Note that sequential stages of change in the Git repository are marked by
tags `before-change`, `change-middle`, `after-change`.
--
Ticket URL: <https://code.djangoproject.com/ticket/30513>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.186c4fcce5f5ae1196361e6af1dbc589%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.