diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py index b58e6a7faf..83591b7185 100644 --- a/django/db/backends/sqlite3/introspection.py +++ b/django/db/backends/sqlite3/introspection.py @@ -65,7 +65,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): relations = {} # Schema for this table - cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s", [table_name]) + cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"]) results = cursor.fetchone()[0].strip() results = results[results.index('(')+1:results.rindex(')')] diff --git a/tests/regressiontests/introspection/tests.py b/tests/regressiontests/introspection/tests.py index 1454e1e3e5..394ebcb636 100644 --- a/tests/regressiontests/introspection/tests.py +++ b/tests/regressiontests/introspection/tests.py @@ -5,11 +5,6 @@ from django.utils import functional from models import Reporter, Article -try: - set -except NameError: - from sets import Set as set # Python 2.3 fallback - # # The introspection module is optional, so methods tested here might raise # NotImplementedError. This is perfectly acceptable behavior for the backend @@ -76,8 +71,10 @@ class IntrospectionTests(TestCase): def test_get_table_description_types(self): cursor = connection.cursor() desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table) - self.assertEqual([datatype(r[1], r) for r in desc], - ['IntegerField', 'CharField', 'CharField', 'CharField']) + self.assertEqual( + [datatype(r[1], r) for r in desc], + ['IntegerField', 'CharField', 'CharField', 'CharField'] + ) # Regression test for #9991 - 'real' types in postgres if settings.DATABASE_ENGINE.startswith('postgresql'):