mirror of
https://github.com/django/django.git
synced 2025-01-03 15:06:09 +00:00
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.
This commit is contained in:
parent
0d9872fc9a
commit
27375ad50e
@ -120,6 +120,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _using_sql(self, new_field, old_field):
|
def _using_sql(self, new_field, old_field):
|
||||||
|
if new_field.generated:
|
||||||
|
return ""
|
||||||
using_sql = " USING %(column)s::%(type)s"
|
using_sql = " USING %(column)s::%(type)s"
|
||||||
new_internal_type = new_field.get_internal_type()
|
new_internal_type = new_field.get_internal_type()
|
||||||
old_internal_type = old_field.get_internal_type()
|
old_internal_type = old_field.get_internal_type()
|
||||||
|
@ -6415,6 +6415,37 @@ class OperationTests(OperationTestBase):
|
|||||||
operation.database_backwards(app_label, editor, new_state, project_state)
|
operation.database_backwards(app_label, editor, new_state, project_state)
|
||||||
self.assertColumnNotExists(f"{app_label}_pony", "modified_pink")
|
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")
|
@skipUnlessDBFeature("supports_stored_generated_columns")
|
||||||
def test_add_generated_field_stored(self):
|
def test_add_generated_field_stored(self):
|
||||||
self._test_add_generated_field(db_persist=True)
|
self._test_add_generated_field(db_persist=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user