Fixed #29569 -- Fixed Cast() with AutoField and BigAutoField.

This commit is contained in:
Mariusz Felisiak 2018-07-25 08:00:11 +02:00 committed by GitHub
parent 6429961418
commit ac25dd1f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 0 deletions

View File

@ -18,6 +18,8 @@ class DatabaseOperations(BaseDatabaseOperations):
'PositiveIntegerField': (0, 4294967295), 'PositiveIntegerField': (0, 4294967295),
} }
cast_data_types = { cast_data_types = {
'AutoField': 'signed integer',
'BigAutoField': 'signed integer',
'CharField': 'char(%(max_length)s)', 'CharField': 'char(%(max_length)s)',
'TextField': 'char', 'TextField': 'char',
'IntegerField': 'signed integer', 'IntegerField': 'signed integer',

View File

@ -52,6 +52,8 @@ END;
# Oracle doesn't support string without precision; use the max string size. # Oracle doesn't support string without precision; use the max string size.
cast_char_field_without_max_length = 'NVARCHAR2(2000)' cast_char_field_without_max_length = 'NVARCHAR2(2000)'
cast_data_types = { cast_data_types = {
'AutoField': 'NUMBER(11)',
'BigAutoField': 'NUMBER(19)',
'TextField': cast_char_field_without_max_length, 'TextField': cast_char_field_without_max_length,
} }

View File

@ -8,6 +8,10 @@ from django.db.backends.base.operations import BaseDatabaseOperations
class DatabaseOperations(BaseDatabaseOperations): class DatabaseOperations(BaseDatabaseOperations):
cast_char_field_without_max_length = 'varchar' cast_char_field_without_max_length = 'varchar'
explain_prefix = 'EXPLAIN' explain_prefix = 'EXPLAIN'
cast_data_types = {
'AutoField': 'integer',
'BigAutoField': 'bigint',
}
def unification_cast_sql(self, output_field): def unification_cast_sql(self, output_field):
internal_type = output_field.get_internal_type() internal_type = output_field.get_internal_type()

View File

@ -39,6 +39,8 @@ class CastTests(TestCase):
def test_cast_to_integer(self): def test_cast_to_integer(self):
for field_class in ( for field_class in (
models.AutoField,
models.BigAutoField,
models.IntegerField, models.IntegerField,
models.BigIntegerField, models.BigIntegerField,
models.SmallIntegerField, models.SmallIntegerField,