Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21097 - Added DatabaseFeature.can_introspect_autofield

  • Loading branch information...
commit c89d80e2cc9bf1f401aa3af4047bdc6f3dc5bfa4 1 parent 6feb751
Michael Manfre authored September 12, 2013 akaariai committed September 14, 2013
7  django/core/management/commands/inspectdb.py
@@ -104,8 +104,11 @@ def handle_inspection(self, options):
104 104
 
105 105
                 # Don't output 'id = meta.AutoField(primary_key=True)', because
106 106
                 # that's assumed if it doesn't exist.
107  
-                if att_name == 'id' and field_type == 'AutoField(' and extra_params == {'primary_key': True}:
108  
-                    continue
  107
+                if att_name == 'id' and extra_params == {'primary_key': True}:
  108
+                    if field_type == 'AutoField(':
  109
+                        continue
  110
+                    elif field_type == 'IntegerField(' and not connection.features.can_introspect_autofield:
  111
+                        comment_notes.append('AutoField?')
109 112
 
110 113
                 # Add 'null' and 'blank', if the 'null_ok' flag was present in the
111 114
                 # table description.
3  django/db/backends/__init__.py
@@ -627,6 +627,9 @@ class BaseDatabaseFeatures(object):
627 627
     # which can't do it for MyISAM tables
628 628
     can_introspect_foreign_keys = True
629 629
 
  630
+    # Can the backend introspect an AutoField, instead of an IntegerField?
  631
+    can_introspect_autofield = False
  632
+
630 633
     # Support for the DISTINCT ON clause
631 634
     can_distinct_on_fields = False
632 635
 
3  tests/inspectdb/tests.py
@@ -42,7 +42,8 @@ def assertFieldType(name, definition):
42 42
             out_def = re.search(r'^\s*%s = (models.*)$' % name, output, re.MULTILINE).groups()[0]
43 43
             self.assertEqual(definition, out_def)
44 44
 
45  
-        assertFieldType('id', "models.IntegerField(primary_key=True)")
  45
+        if not connection.features.can_introspect_autofield:
  46
+            assertFieldType('id', "models.IntegerField(primary_key=True) # AutoField?")
46 47
         assertFieldType('big_int_field', "models.BigIntegerField()")
47 48
         if connection.vendor == 'mysql':
48 49
             # No native boolean type on MySQL
5  tests/introspection/tests.py
@@ -66,8 +66,9 @@ def test_get_table_description_types(self):
66 66
         # field type on MySQL
67 67
         self.assertEqual(
68 68
             [datatype(r[1], r) for r in desc],
69  
-            ['IntegerField', 'CharField', 'CharField', 'CharField',
70  
-             'BigIntegerField', 'BinaryField' if connection.vendor != 'mysql' else 'TextField']
  69
+            ['AutoField' if connection.features.can_introspect_autofield else 'IntegerField',
  70
+             'CharField', 'CharField', 'CharField', 'BigIntegerField',
  71
+             'BinaryField' if connection.vendor != 'mysql' else 'TextField']
71 72
         )
72 73
 
73 74
     # The following test fails on Oracle due to #17202 (can't correctly

0 notes on commit c89d80e

Please sign in to comment.
Something went wrong with that request. Please try again.