diff options
| author | Ben Cail <bcail@crossway.org> | 2024-03-07 15:34:16 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-03-14 20:56:43 +0100 |
| commit | 593067a8ee43e2167c5ffc92e3cc3c5e40ec4aa4 (patch) | |
| tree | a4c57bf9c2726e1c3eb088fbbc3a8de70128641b /tests | |
| parent | 3d7235c67b5b0569890411eeba8db2b1e02c89c4 (diff) | |
Fixed #28541 -- Fixed migrations crash when changing primary key on SQLite.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_operations.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 3845381454..b058543801 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -2802,6 +2802,42 @@ class OperationTests(OperationTestBase): (f"{app_label}_pony", "id"), ) + def test_alter_id_pk_to_uuid_pk(self): + app_label = "test_alidpktuuidpk" + project_state = self.set_up_test_model(app_label) + new_state = project_state.clone() + # Add UUID field. + operation = migrations.AddField("Pony", "uuid", models.UUIDField()) + operation.state_forwards(app_label, new_state) + with connection.schema_editor() as editor: + operation.database_forwards(app_label, editor, project_state, new_state) + # Remove ID. + project_state = new_state + new_state = new_state.clone() + operation = migrations.RemoveField("Pony", "id") + operation.state_forwards(app_label, new_state) + with connection.schema_editor() as editor: + operation.database_forwards(app_label, editor, project_state, new_state) + self.assertColumnNotExists(f"{app_label}_pony", "id") + # Rename to ID. + project_state = new_state + new_state = new_state.clone() + operation = migrations.RenameField("Pony", "uuid", "id") + operation.state_forwards(app_label, new_state) + with connection.schema_editor() as editor: + operation.database_forwards(app_label, editor, project_state, new_state) + self.assertColumnNotExists(f"{app_label}_pony", "uuid") + self.assertColumnExists(f"{app_label}_pony", "id") + # Change to a primary key. + project_state = new_state + new_state = new_state.clone() + operation = migrations.AlterField( + "Pony", "id", models.UUIDField(primary_key=True) + ) + operation.state_forwards(app_label, new_state) + with connection.schema_editor() as editor: + operation.database_forwards(app_label, editor, project_state, new_state) + @skipUnlessDBFeature("supports_foreign_keys") def test_alter_field_reloads_state_on_fk_with_to_field_target_type_change(self): app_label = "test_alflrsfkwtflttc" |
