diff options
| author | Paolo Melchiorre <paolo@melchiorre.org> | 2023-09-27 22:24:04 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-28 05:50:42 +0200 |
| commit | e7e8eb44a30bcab004a582760752b5eb3fcd6e91 (patch) | |
| tree | 8869685c22d597a66c80584abf2d7fd20fa2980d /tests/schema | |
| parent | 5e4b75b78a7a84bc30170c2b8e7434525e745c1b (diff) | |
Fixed #34877 -- Fixed migrations crash when adding GeneratedField with output_field with params.
Diffstat (limited to 'tests/schema')
| -rw-r--r-- | tests/schema/tests.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 340399c0bf..68b6442794 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -2,6 +2,7 @@ import datetime import itertools import unittest from copy import copy +from decimal import Decimal from unittest import mock from django.core.exceptions import FieldError @@ -52,7 +53,7 @@ from django.db.models import ( Value, ) from django.db.models.fields.json import KT, KeyTextTransform -from django.db.models.functions import Abs, Cast, Collate, Lower, Random, Upper +from django.db.models.functions import Abs, Cast, Collate, Lower, Random, Round, Upper from django.db.models.indexes import IndexExpression from django.db.transaction import TransactionManagementError, atomic from django.test import TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature @@ -830,6 +831,23 @@ class SchemaTests(TransactionTestCase): ) @isolate_apps("schema") + @skipUnlessDBFeature("supports_stored_generated_columns") + def test_add_generated_field_with_output_field(self): + class GeneratedFieldOutputFieldModel(Model): + price = DecimalField(max_digits=7, decimal_places=2) + vat_price = GeneratedField( + expression=Round(F("price") * Value(Decimal("1.22")), 2), + db_persist=True, + output_field=DecimalField(max_digits=8, decimal_places=2), + ) + + class Meta: + app_label = "schema" + + with connection.schema_editor() as editor: + editor.create_model(GeneratedFieldOutputFieldModel) + + @isolate_apps("schema") def test_add_auto_field(self): class AddAutoFieldModel(Model): name = CharField(max_length=255, primary_key=True) |
