diff options
| author | lufafajoshua <77637648+lufafajoshua@users.noreply.github.com> | 2024-12-09 15:37:05 +0300 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-12-17 11:27:25 +0100 |
| commit | 27375ad50ea3306844aab8122de13e9b3e0d1189 (patch) | |
| tree | 669b05e97a3967a611af0449ad1a1c8c7abe045f /tests/migrations | |
| parent | 0d9872fc9a70ef6966930c68c68febea7eb60ede (diff) | |
Fixed #35969 -- Disallowed specifying a USING clause for altered generated field.
PostgreSQL versions 16.5 and above no longer permit the use
of a USING clause when changing the type of a generated column.
Diffstat (limited to 'tests/migrations')
| -rw-r--r-- | tests/migrations/test_operations.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 33a7b6dc3d..d95e382285 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -6416,6 +6416,37 @@ class OperationTests(OperationTestBase): self.assertColumnNotExists(f"{app_label}_pony", "modified_pink") @skipUnlessDBFeature("supports_stored_generated_columns") + def test_generated_field_changes_output_field(self): + app_label = "test_gfcof" + operation = migrations.AddField( + "Pony", + "modified_pink", + models.GeneratedField( + expression=F("pink") + F("pink"), + output_field=models.IntegerField(), + db_persist=True, + ), + ) + from_state, to_state = self.make_test_state(app_label, operation) + # Add generated column. + with connection.schema_editor() as editor: + operation.database_forwards(app_label, editor, from_state, to_state) + # Update output_field used in the generated field. + operation = migrations.AlterField( + "Pony", + "modified_pink", + models.GeneratedField( + expression=F("pink") + F("pink"), + output_field=models.DecimalField(decimal_places=2, max_digits=16), + db_persist=True, + ), + ) + from_state = to_state.clone() + to_state = self.apply_operations(app_label, from_state, [operation]) + with connection.schema_editor() as editor: + operation.database_forwards(app_label, editor, from_state, to_state) + + @skipUnlessDBFeature("supports_stored_generated_columns") def test_add_generated_field_stored(self): self._test_add_generated_field(db_persist=True) |
