Fixed #21097 - Added DatabaseFeature.can_introspect_autofield
This commit is contained in:
parent
6feb75129f
commit
c89d80e2cc
|
@ -104,8 +104,11 @@ class Command(NoArgsCommand):
|
||||||
|
|
||||||
# Don't output 'id = meta.AutoField(primary_key=True)', because
|
# Don't output 'id = meta.AutoField(primary_key=True)', because
|
||||||
# that's assumed if it doesn't exist.
|
# that's assumed if it doesn't exist.
|
||||||
if att_name == 'id' and field_type == 'AutoField(' and extra_params == {'primary_key': True}:
|
if att_name == 'id' and extra_params == {'primary_key': True}:
|
||||||
|
if field_type == 'AutoField(':
|
||||||
continue
|
continue
|
||||||
|
elif field_type == 'IntegerField(' and not connection.features.can_introspect_autofield:
|
||||||
|
comment_notes.append('AutoField?')
|
||||||
|
|
||||||
# Add 'null' and 'blank', if the 'null_ok' flag was present in the
|
# Add 'null' and 'blank', if the 'null_ok' flag was present in the
|
||||||
# table description.
|
# table description.
|
||||||
|
|
|
@ -627,6 +627,9 @@ class BaseDatabaseFeatures(object):
|
||||||
# which can't do it for MyISAM tables
|
# which can't do it for MyISAM tables
|
||||||
can_introspect_foreign_keys = True
|
can_introspect_foreign_keys = True
|
||||||
|
|
||||||
|
# Can the backend introspect an AutoField, instead of an IntegerField?
|
||||||
|
can_introspect_autofield = False
|
||||||
|
|
||||||
# Support for the DISTINCT ON clause
|
# Support for the DISTINCT ON clause
|
||||||
can_distinct_on_fields = False
|
can_distinct_on_fields = False
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,8 @@ class InspectDBTestCase(TestCase):
|
||||||
out_def = re.search(r'^\s*%s = (models.*)$' % name, output, re.MULTILINE).groups()[0]
|
out_def = re.search(r'^\s*%s = (models.*)$' % name, output, re.MULTILINE).groups()[0]
|
||||||
self.assertEqual(definition, out_def)
|
self.assertEqual(definition, out_def)
|
||||||
|
|
||||||
assertFieldType('id', "models.IntegerField(primary_key=True)")
|
if not connection.features.can_introspect_autofield:
|
||||||
|
assertFieldType('id', "models.IntegerField(primary_key=True) # AutoField?")
|
||||||
assertFieldType('big_int_field', "models.BigIntegerField()")
|
assertFieldType('big_int_field', "models.BigIntegerField()")
|
||||||
if connection.vendor == 'mysql':
|
if connection.vendor == 'mysql':
|
||||||
# No native boolean type on MySQL
|
# No native boolean type on MySQL
|
||||||
|
|
|
@ -66,8 +66,9 @@ class IntrospectionTests(TestCase):
|
||||||
# field type on MySQL
|
# field type on MySQL
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[datatype(r[1], r) for r in desc],
|
[datatype(r[1], r) for r in desc],
|
||||||
['IntegerField', 'CharField', 'CharField', 'CharField',
|
['AutoField' if connection.features.can_introspect_autofield else 'IntegerField',
|
||||||
'BigIntegerField', 'BinaryField' if connection.vendor != 'mysql' else 'TextField']
|
'CharField', 'CharField', 'CharField', 'BigIntegerField',
|
||||||
|
'BinaryField' if connection.vendor != 'mysql' else 'TextField']
|
||||||
)
|
)
|
||||||
|
|
||||||
# The following test fails on Oracle due to #17202 (can't correctly
|
# The following test fails on Oracle due to #17202 (can't correctly
|
||||||
|
|
Loading…
Reference in New Issue