diff --git a/django/db/backends/postgresql_psycopg2/introspection.py b/django/db/backends/postgresql_psycopg2/introspection.py
index 2ce579a..0027ec5 100644
a
|
b
|
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
34 | 34 | |
35 | 35 | def get_table_description(self, cursor, table_name): |
36 | 36 | "Returns a description of the table, with the DB-API cursor.description interface." |
| 37 | # As cursor.description does not return reliably the nullable property, |
| 38 | # we have to query the information_schema (#7783) |
| 39 | cursor.execute(""" |
| 40 | SELECT column_name, is_nullable |
| 41 | FROM information_schema.columns |
| 42 | WHERE table_name = %s""", [table_name]) |
| 43 | null_map = dict(cursor.fetchall()) |
37 | 44 | cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)) |
38 | | return cursor.description |
| 45 | return [tuple([item for item in line[:6]] + [null_map[line[0]]==u'YES']) |
| 46 | for line in cursor.description] |
39 | 47 | |
40 | 48 | def get_relations(self, cursor, table_name): |
41 | 49 | """ |
diff --git a/tests/regressiontests/introspection/models.py b/tests/regressiontests/introspection/models.py
index da12f6e..3b8383e 100644
a
|
b
|
class Reporter(models.Model):
|
5 | 5 | first_name = models.CharField(max_length=30) |
6 | 6 | last_name = models.CharField(max_length=30) |
7 | 7 | email = models.EmailField() |
8 | | facebook_user_id = models.BigIntegerField() |
| 8 | facebook_user_id = models.BigIntegerField(null=True) |
9 | 9 | |
10 | 10 | def __unicode__(self): |
11 | 11 | return u"%s %s" % (self.first_name, self.last_name) |
diff --git a/tests/regressiontests/introspection/tests.py b/tests/regressiontests/introspection/tests.py
index 1835064..fa2b6c5 100644
a
|
b
|
class IntrospectionTests(TestCase):
|
78 | 78 | ['IntegerField', 'CharField', 'CharField', 'CharField', 'BigIntegerField'] |
79 | 79 | ) |
80 | 80 | |
| 81 | def test_get_table_description_nullable(self): |
| 82 | cursor = connection.cursor() |
| 83 | desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table) |
| 84 | self.assertEqual( |
| 85 | [r[6] for r in desc], |
| 86 | [False, False, False, False, True] |
| 87 | ) |
| 88 | |
81 | 89 | # Regression test for #9991 - 'real' types in postgres |
82 | 90 | @skipUnlessDBFeature('has_real_datatype') |
83 | 91 | def test_postgresql_real_type(self): |