diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index 70bc5baee3..73e8a19e76 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -142,7 +142,7 @@ class Command(BaseCommand): if att_name == 'id' and extra_params == {'primary_key': True}: if field_type == 'AutoField(': continue - elif field_type == 'IntegerField(' and not connection.features.can_introspect_autofield: + elif field_type == connection.features.introspected_field_types['AutoField'] + '(': comment_notes.append('AutoField?') # Add 'null' and 'blank', if the 'null_ok' flag was present in the diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py index 533dbc7fec..10bd4077dc 100644 --- a/django/db/backends/base/features.py +++ b/django/db/backends/base/features.py @@ -125,12 +125,10 @@ class BaseDatabaseFeatures: # which can't do it for MyISAM tables can_introspect_foreign_keys = True - # Can the backend introspect an AutoField, instead of an IntegerField? - can_introspect_autofield = False - # Map fields which some backends may not be able to differentiate to the # field it's introspected as. introspected_field_types = { + 'AutoField': 'AutoField', 'BigAutoField': 'BigAutoField', 'BigIntegerField': 'BigIntegerField', 'BinaryField': 'BinaryField', diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py index a1a6e4b084..85017012b1 100644 --- a/django/db/backends/mysql/features.py +++ b/django/db/backends/mysql/features.py @@ -14,7 +14,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_forward_references = False supports_regex_backreferencing = False supports_date_lookup_using_string = False - can_introspect_autofield = True supports_index_column_ordering = False supports_timezones = False requires_explicit_null_ordering_when_grouping = True diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py index 66dfdd4399..c497a7c0b6 100644 --- a/django/db/backends/oracle/features.py +++ b/django/db/backends/oracle/features.py @@ -11,7 +11,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): has_select_for_update_of = True select_for_update_of_column = True can_return_columns_from_insert = True - can_introspect_autofield = True supports_subqueries_in_group_by = False supports_transactions = True supports_timezones = False diff --git a/django/db/backends/sqlite3/features.py b/django/db/backends/sqlite3/features.py index 08c8eb70b9..84358838db 100644 --- a/django/db/backends/sqlite3/features.py +++ b/django/db/backends/sqlite3/features.py @@ -18,7 +18,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_timezones = False max_query_params = 999 supports_mixed_date_datetime_comparisons = False - can_introspect_autofield = True supports_transactions = True atomic_transactions = False can_rollback_ddl = True diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt index c5f5bb7707..94084ceba8 100644 --- a/docs/releases/3.2.txt +++ b/docs/releases/3.2.txt @@ -250,6 +250,7 @@ backends. * The new ``DatabaseFeatures.introspected_field_types`` property replaces these features: + * ``can_introspect_autofield`` * ``can_introspect_big_integer_field`` * ``can_introspect_binary_field`` * ``can_introspect_decimal_field`` diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 7ed96abd37..583512cc09 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -99,8 +99,9 @@ class InspectDBTestCase(TestCase): assertFieldType = self.make_field_type_asserter() introspected_field_types = connection.features.introspected_field_types - if not connection.features.can_introspect_autofield: - assertFieldType('id', "models.IntegerField(primary_key=True) # AutoField?") + auto_field_type = connection.features.introspected_field_types['AutoField'] + if auto_field_type != 'AutoField': + assertFieldType('id', "models.%s(primary_key=True) # AutoField?" % auto_field_type) assertFieldType('big_int_field', 'models.%s()' % introspected_field_types['BigIntegerField']) diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py index 8ca5c3af3b..9335250c89 100644 --- a/tests/introspection/tests.py +++ b/tests/introspection/tests.py @@ -80,7 +80,7 @@ class IntrospectionTests(TransactionTestCase): self.assertEqual( [connection.introspection.get_field_type(r[1], r) for r in desc], [ - 'AutoField' if connection.features.can_introspect_autofield else 'IntegerField', + connection.features.introspected_field_types['AutoField'], 'CharField', 'CharField', 'CharField', @@ -108,7 +108,6 @@ class IntrospectionTests(TransactionTestCase): [False, nullable_by_backend, nullable_by_backend, nullable_by_backend, True, True, False, False] ) - @skipUnlessDBFeature('can_introspect_autofield') def test_bigautofield(self): with connection.cursor() as cursor: desc = connection.introspection.get_table_description(cursor, City._meta.db_table) @@ -117,7 +116,6 @@ class IntrospectionTests(TransactionTestCase): [connection.introspection.get_field_type(r[1], r) for r in desc], ) - @skipUnlessDBFeature('can_introspect_autofield') def test_smallautofield(self): with connection.cursor() as cursor: desc = connection.introspection.get_table_description(cursor, Country._meta.db_table)