﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30513	Impossible migration (with a change of model base) is not noticed.	Victor Porton	nobody	"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`."	Bug	closed	Migrations	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
