From 84ca7b860223d9211976be1a179c727784defc7a Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 7 Nov 2020 14:26:01 -0500 Subject: [PATCH] Removed hardcoded pks in migrations' test_alter_order_with_respect_to. --- tests/migrations/test_base.py | 2 +- tests/migrations/test_operations.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/migrations/test_base.py b/tests/migrations/test_base.py index 28a57f552d..9adc0d5264 100644 --- a/tests/migrations/test_base.py +++ b/tests/migrations/test_base.py @@ -248,7 +248,7 @@ class OperationTestBase(MigrationTestBase): [ ('id', models.AutoField(primary_key=True)), ('pony', models.ForeignKey('Pony', models.CASCADE)), - ('friend', models.ForeignKey('self', models.CASCADE)) + ('friend', models.ForeignKey('self', models.CASCADE, null=True)) ], )) if mti_model: diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 4111e7f326..38ad6a2d18 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -2541,8 +2541,12 @@ class OperationTests(OperationTestBase): # Create some rows before alteration rendered_state = project_state.apps pony = rendered_state.get_model("test_alorwrtto", "Pony").objects.create(weight=50) - rendered_state.get_model("test_alorwrtto", "Rider").objects.create(pony=pony, friend_id=1) - rendered_state.get_model("test_alorwrtto", "Rider").objects.create(pony=pony, friend_id=2) + rider1 = rendered_state.get_model("test_alorwrtto", "Rider").objects.create(pony=pony) + rider1.friend = rider1 + rider1.save() + rider2 = rendered_state.get_model("test_alorwrtto", "Rider").objects.create(pony=pony) + rider2.friend = rider2 + rider2.save() # Test the database alteration with connection.schema_editor() as editor: operation.database_forwards("test_alorwrtto", editor, project_state, new_state)