Skip to content

Commit

Permalink
Fixed #29209 -- Fixed Cast() with TextField on MySQL and Oracle.
Browse files Browse the repository at this point in the history
  • Loading branch information
sir-sigurd authored and timgraham committed Mar 13, 2018
1 parent c12745f commit d696fcc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions django/db/backends/mysql/operations.py
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions django/db/backends/oracle/operations.py
Expand Up @@ -51,6 +51,9 @@ class DatabaseOperations(BaseDatabaseOperations):

# 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 """
Expand Down
3 changes: 3 additions & 0 deletions tests/db_functions/test_cast.py
Expand Up @@ -74,3 +74,6 @@ def test_expression_wrapped_with_parentheses_on_postgresql(self):
"""
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')

0 comments on commit d696fcc

Please sign in to comment.