Fixed #15170 -- Skip the inspectdb test under MySQL/MyISAM, because it 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
This commit is contained in:
parent
76fb2bb0e2
commit
74d485c4ec
|
@ -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 @@ class BaseDatabaseFeatures(object):
|
|||
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 BaseDatabaseFeatures(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):
|
||||
"""
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue