Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@freakboy3742 freakboy3742 authored
View
8 django/db/backends/__init__.py
@@ -168,6 +168,7 @@ class BaseDatabaseFeatures(object):
_confirmed = False
supports_transactions = None
supports_stddev = None
+ can_introspect_foreign_keys = None
def __init__(self, connection):
self.connection = connection
@@ -177,6 +178,7 @@ def confirm(self):
self._confirmed = True
self.supports_transactions = self._supports_transactions()
self.supports_stddev = self._supports_stddev()
+ self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
def _supports_transactions(self):
"Confirm support for transactions"
@@ -201,6 +203,12 @@ class StdDevPop(object):
except NotImplementedError:
self.supports_stddev = False
+ def _can_introspect_foreign_keys(self):
+ "Confirm support for introspected foreign keys"
+ # Every database can do this reliably, except MySQL,
+ # which can't do it for MyISAM tables
+ return True
+
class BaseDatabaseOperations(object):
"""
View
13 django/db/backends/mysql/base.py
@@ -133,6 +133,19 @@ class DatabaseFeatures(BaseDatabaseFeatures):
requires_explicit_null_ordering_when_grouping = True
allows_primary_key_0 = False
+ def _can_introspect_foreign_keys(self):
+ "Confirm support for introspected foreign keys"
+ cursor = self.connection.cursor()
+ cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)')
+ # This command is MySQL specific; the second column
+ # will tell you the default table type of the created
+ # table. Since all Django's test tables will have the same
+ # table type, that's enough to evaluate the feature.
+ cursor.execute('SHOW TABLE STATUS WHERE Name="INTROSPECT_TEST"')
+ result = cursor.fetchone()
+ cursor.execute('DROP TABLE INTROSPECT_TEST')
+ return result[1] != 'MyISAM'
+
class DatabaseOperations(BaseDatabaseOperations):
compiler_module = "django.db.backends.mysql.compiler"
View
4 tests/regressiontests/inspectdb/tests.py
@@ -1,10 +1,12 @@
from StringIO import StringIO
from django.core.management import call_command
-from django.test import TestCase
+from django.test import TestCase, skipUnlessDBFeature
class InspectDBTestCase(TestCase):
+
+ @skipUnlessDBFeature('can_introspect_foreign_keys')
def test_attribute_name_not_python_keyword(self):
out = StringIO()
call_command('inspectdb', stdout=out)
Please sign in to comment.
Something went wrong with that request. Please try again.