#30513 closed Bug (duplicate)
Impossible migration (with a change of model base) is not noticed.
| Reported by: | Victor Porton | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
- Extract the attached Git repository. (It contains among other migrations automatically created with
makemigrations, one of the migrations was made with choosing the option2) 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).)
- 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.
Attachments (1)
Change History (4)
by , 6 years ago
| Attachment: | bug.tar.gz added |
|---|
comment:1 by , 6 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
| Summary: | Impossible migration (with a change of model base) is not noticed → Impossible migration (with a change of model base) is not noticed. |
| Version: | 2.2 → master |
Adding migrations.AlterModelBases() to a migration operations should solve this issue.
Marking as a duplicate of #23521.
The Git repository with stages of the bug appearance