Skip to content

Commit

Permalink
Fixed #23357 -- Added small int introspection support to MySQL backend.
Browse files Browse the repository at this point in the history
In the MySQL backend, updated the can_introspect_small_integer feature
flag to True. In data_types_reverse, map FIELD_TYPE.SHORT to a
SmallIntegerField. Added test to verify introspecting SmallIntegerFields
and fixed existing tests influenced by this change.
  • Loading branch information
jdufresne authored and charettes committed Aug 27, 2014
1 parent a81af7f commit f0d3dd4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions django/db/backends/mysql/base.py
Expand Up @@ -178,6 +178,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_date_lookup_using_string = False supports_date_lookup_using_string = False
can_introspect_binary_field = False can_introspect_binary_field = False
can_introspect_boolean_field = False can_introspect_boolean_field = False
can_introspect_small_integer_field = True
supports_timezones = False supports_timezones = False
requires_explicit_null_ordering_when_grouping = True requires_explicit_null_ordering_when_grouping = True
allows_auto_pk_0 = False allows_auto_pk_0 = False
Expand Down
2 changes: 1 addition & 1 deletion django/db/backends/mysql/introspection.py
Expand Up @@ -21,7 +21,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
FIELD_TYPE.INT24: 'IntegerField', FIELD_TYPE.INT24: 'IntegerField',
FIELD_TYPE.LONG: 'IntegerField', FIELD_TYPE.LONG: 'IntegerField',
FIELD_TYPE.LONGLONG: 'BigIntegerField', FIELD_TYPE.LONGLONG: 'BigIntegerField',
FIELD_TYPE.SHORT: 'IntegerField', FIELD_TYPE.SHORT: 'SmallIntegerField',
FIELD_TYPE.STRING: 'CharField', FIELD_TYPE.STRING: 'CharField',
FIELD_TYPE.TIME: 'TimeField', FIELD_TYPE.TIME: 'TimeField',
FIELD_TYPE.TIMESTAMP: 'DateTimeField', FIELD_TYPE.TIMESTAMP: 'DateTimeField',
Expand Down
1 change: 1 addition & 0 deletions tests/introspection/models.py
Expand Up @@ -11,6 +11,7 @@ class Reporter(models.Model):
email = models.EmailField() email = models.EmailField()
facebook_user_id = models.BigIntegerField(null=True) facebook_user_id = models.BigIntegerField(null=True)
raw_data = models.BinaryField(null=True) raw_data = models.BinaryField(null=True)
small_int = models.SmallIntegerField()


class Meta: class Meta:
unique_together = ('first_name', 'last_name') unique_together = ('first_name', 'last_name')
Expand Down
5 changes: 3 additions & 2 deletions tests/introspection/tests.py
Expand Up @@ -59,7 +59,8 @@ def test_get_table_description_types(self):
['AutoField' if connection.features.can_introspect_autofield else 'IntegerField', ['AutoField' if connection.features.can_introspect_autofield else 'IntegerField',
'CharField', 'CharField', 'CharField', 'CharField', 'CharField', 'CharField',
'BigIntegerField' if connection.features.can_introspect_big_integer_field else 'IntegerField', 'BigIntegerField' if connection.features.can_introspect_big_integer_field else 'IntegerField',
'BinaryField' if connection.features.can_introspect_binary_field else 'TextField'] 'BinaryField' if connection.features.can_introspect_binary_field else 'TextField',
'SmallIntegerField' if connection.features.can_introspect_small_integer_field else 'IntegerField']
) )


# The following test fails on Oracle due to #17202 (can't correctly # The following test fails on Oracle due to #17202 (can't correctly
Expand All @@ -80,7 +81,7 @@ def test_get_table_description_nullable(self):
nullable_by_backend = connection.features.interprets_empty_strings_as_nulls nullable_by_backend = connection.features.interprets_empty_strings_as_nulls
self.assertEqual( self.assertEqual(
[r[6] for r in desc], [r[6] for r in desc],
[False, nullable_by_backend, nullable_by_backend, nullable_by_backend, True, True] [False, nullable_by_backend, nullable_by_backend, nullable_by_backend, True, True, False]
) )


# Regression test for #9991 - 'real' types in postgres # Regression test for #9991 - 'real' types in postgres
Expand Down

0 comments on commit f0d3dd4

Please sign in to comment.