#30966: Migration crashes due to foreign key issue, depending on otherwise
irrelevant order on MySQL.
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration mySQL | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Markus Holtermann):
This is a minimal failing test
{{{#!diff
diff --git a/tests/migrations/test_state.py
b/tests/migrations/test_state.py
index e9bdac93c5..9140609bb6 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -928,6 +928,64 @@ class StateTests(SimpleTestCase):
choices_field = Author._meta.get_field('choice')
self.assertEqual(list(choices_field.choices), choices)
+ def test_reload_related_models_on_non_relational_fields(self):
+ """
+ #30966 - Even when fields on a model change that are not involved
in
+ a relation, the model gets reloaded. Ensure that other models
pointing
+ to or from it are reloaded accordingly.
+
+ User <-- Domain <-- RRset
+ ^
+ +-- Token
+ """
+ project_state = ProjectState()
+ # Render project state to simulate initial migration state
+ project_state.apps
+ project_state.add_model(ModelState(
+ "migrations",
+ "User",
+ [
+ ("id", models.AutoField(primary_key=True)),
+ ("email", models.EmailField(max_length=191,
unique=True)),
+ ]
+ ))
+ project_state.add_model(ModelState(
+ "migrations",
+ "Domain",
+ [
+ ("id", models.AutoField(primary_key=True)),
+ ("owner", models.ForeignKey("migrations.User",
models.SET_NULL)),
+ ]
+ ))
+ project_state.add_model(ModelState(
+ "migrations",
+ "RRset",
+ [
+ ("id", models.AutoField(primary_key=True)),
+ ("subname", models.CharField(blank=True,
max_length=178)),
+ ("domain", models.ForeignKey("migrations.Domain",
models.SET_NULL)),
+ ]
+ ))
+ project_state.add_model(ModelState(
+ "migrations",
+ "Token",
+ [
+ ("id", models.AutoField(primary_key=True)),
+ ("user", models.ForeignKey("migrations.User",
models.SET_NULL)),
+ ]
+ ))
+ AlterField(
+ model_name="RRset",
+ name="subname",
+ field=models.CharField(blank=False, max_length=178),
+ ).state_forwards("migrations", project_state)
+
+ all_models = project_state.apps.all_models["migrations"]
+ assert (
+ all_models['token']._meta.get_field('user').related_model
+ is all_models['user']
+ ), "Models are not identical"
+
class ModelStateTests(SimpleTestCase):
def test_custom_model_base(self):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30966#comment:16>
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/072.cca411c8c889ff69665aeaff0c292eb1%40djangoproject.com.