From 74d485c4ec2b754578482af98e3e8258d1575ad0 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 1 Feb 2011 14:42:52 +0000 Subject: [PATCH] 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 --- django/db/backends/__init__.py | 8 ++++++++ django/db/backends/mysql/base.py | 13 +++++++++++++ tests/regressiontests/inspectdb/tests.py | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 3979c9ac8a..2abc81ae5d 100644 --- a/django/db/backends/__init__.py +++ b/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 @@ 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): """ diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 9b49a8f0ea..98233c7329 100644 --- a/django/db/backends/mysql/base.py +++ b/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" diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py index c6f9e6f88a..683e6e9cf7 100644 --- a/tests/regressiontests/inspectdb/tests.py +++ b/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)