summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2018-03-13 06:57:14 +0500
committerTim Graham <timograham@gmail.com>2018-03-12 21:57:14 -0400
commitd696fccae6ea0868855aa28f8d2bc2f7f77ac208 (patch)
treebb0c35b94e9c1705411168cef3fcfdba6a95f8ad
parentc12745f6826280acb637f9c43cd2c7c2ef3d8761 (diff)
Fixed #29209 -- Fixed Cast() with TextField on MySQL and Oracle.
-rw-r--r--django/db/backends/mysql/operations.py1
-rw-r--r--django/db/backends/oracle/operations.py3
-rw-r--r--tests/db_functions/test_cast.py3
3 files changed, 7 insertions, 0 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index 88e47b95ba..2b85be9c56 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -18,6 +18,7 @@ class DatabaseOperations(BaseDatabaseOperations):
}
cast_data_types = {
'CharField': 'char(%(max_length)s)',
+ 'TextField': 'char',
'IntegerField': 'signed integer',
'BigIntegerField': 'signed integer',
'SmallIntegerField': 'signed integer',
diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py
index 748f606368..d11072bd2c 100644
--- a/django/db/backends/oracle/operations.py
+++ b/django/db/backends/oracle/operations.py
@@ -51,6 +51,9 @@ END;
# Oracle doesn't support string without precision; use the max string size.
cast_char_field_without_max_length = 'NVARCHAR2(2000)'
+ cast_data_types = {
+ 'TextField': cast_char_field_without_max_length,
+ }
def cache_key_culling_sql(self):
return """
diff --git a/tests/db_functions/test_cast.py b/tests/db_functions/test_cast.py
index 12932d95be..d66bec302f 100644
--- a/tests/db_functions/test_cast.py
+++ b/tests/db_functions/test_cast.py
@@ -74,3 +74,6 @@ class CastTests(TestCase):
"""
list(Author.objects.annotate(cast_float=Cast(Avg('age'), models.FloatField())))
self.assertIn('(AVG("db_functions_author"."age"))::double precision', connection.queries[-1]['sql'])
+
+ def test_cast_to_text_field(self):
+ self.assertEqual(Author.objects.values_list(Cast('age', models.TextField()), flat=True).get(), '1')