Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15170 -- Skip the inspectdb test under MySQL/MyISAM, because i…

…t can't differentiate a foreign key from an integer.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15385 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 74d485c4ec2b754578482af98e3e8258d1575ad0 1 parent 76fb2bb
Russell Keith-Magee authored February 01, 2011
8  django/db/backends/__init__.py
@@ -168,6 +168,7 @@ class BaseDatabaseFeatures(object):
168 168
     _confirmed = False
169 169
     supports_transactions = None
170 170
     supports_stddev = None
  171
+    can_introspect_foreign_keys = None
171 172
 
172 173
     def __init__(self, connection):
173 174
         self.connection = connection
@@ -177,6 +178,7 @@ def confirm(self):
177 178
         self._confirmed = True
178 179
         self.supports_transactions = self._supports_transactions()
179 180
         self.supports_stddev = self._supports_stddev()
  181
+        self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
180 182
 
181 183
     def _supports_transactions(self):
182 184
         "Confirm support for transactions"
@@ -201,6 +203,12 @@ class StdDevPop(object):
201 203
         except NotImplementedError:
202 204
             self.supports_stddev = False
203 205
 
  206
+    def _can_introspect_foreign_keys(self):
  207
+        "Confirm support for introspected foreign keys"
  208
+        # Every database can do this reliably, except MySQL,
  209
+        # which can't do it for MyISAM tables
  210
+        return True
  211
+
204 212
 
205 213
 class BaseDatabaseOperations(object):
206 214
     """
13  django/db/backends/mysql/base.py
@@ -133,6 +133,19 @@ class DatabaseFeatures(BaseDatabaseFeatures):
133 133
     requires_explicit_null_ordering_when_grouping = True
134 134
     allows_primary_key_0 = False
135 135
 
  136
+    def _can_introspect_foreign_keys(self):
  137
+        "Confirm support for introspected foreign keys"
  138
+        cursor = self.connection.cursor()
  139
+        cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)')
  140
+        # This command is MySQL specific; the second column
  141
+        # will tell you the default table type of the created
  142
+        # table. Since all Django's test tables will have the same
  143
+        # table type, that's enough to evaluate the feature.
  144
+        cursor.execute('SHOW TABLE STATUS WHERE Name="INTROSPECT_TEST"')
  145
+        result = cursor.fetchone()
  146
+        cursor.execute('DROP TABLE INTROSPECT_TEST')
  147
+        return result[1] != 'MyISAM'
  148
+
136 149
 class DatabaseOperations(BaseDatabaseOperations):
137 150
     compiler_module = "django.db.backends.mysql.compiler"
138 151
 
4  tests/regressiontests/inspectdb/tests.py
... ...
@@ -1,10 +1,12 @@
1 1
 from StringIO import StringIO
2 2
 
3 3
 from django.core.management import call_command
4  
-from django.test import TestCase
  4
+from django.test import TestCase, skipUnlessDBFeature
5 5
 
6 6
 
7 7
 class InspectDBTestCase(TestCase):
  8
+
  9
+    @skipUnlessDBFeature('can_introspect_foreign_keys')
8 10
     def test_attribute_name_not_python_keyword(self):
9 11
         out = StringIO()
10 12
         call_command('inspectdb', stdout=out)

0 notes on commit 74d485c

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