diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 4d4f3c4ecc..3a0c75ebf2 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1082,7 +1082,7 @@ class Value(SQLiteNumericMixin, Expression): def _resolve_output_field(self): if isinstance(self.value, str): - return fields.CharField(max_length=len(self.value)) + return fields.CharField() if isinstance(self.value, bool): return fields.BooleanField() if isinstance(self.value, int): diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 9743d024b1..073e2e9258 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -2227,7 +2227,6 @@ class ValueTests(TestCase): with self.subTest(type=type(value)): expr = Value(value) self.assertIsInstance(expr.output_field, output_field_type) - self.assertEqual(Value("foo").output_field.max_length, 3) def test_resolve_output_field_failure(self): msg = "Cannot resolve expression type, unknown output_field" diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 1298b32caf..72f90c934b 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -842,23 +842,6 @@ class SchemaTests(TransactionTestCase): False, ) - @isolate_apps("schema") - @skipUnlessDBFeature("supports_stored_generated_columns") - def test_add_generated_field_with_string_value(self): - class GeneratedFieldStringValueModel(Model): - value = GeneratedField(expression=Value("static string"), db_persist=True) - - class Meta: - app_label = "schema" - - with CaptureQueriesContext(connection) as ctx: - with connection.schema_editor() as editor: - editor.create_model(GeneratedFieldStringValueModel) - self.assertIs( - any("None" in query["sql"] for query in ctx.captured_queries), - False, - ) - @isolate_apps("schema") @skipUnlessDBFeature("supports_stored_generated_columns") def test_add_generated_field_with_output_field(self):