From c5e2ecae6949d4e89530610d768bbbd563ddc19b Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 17 Sep 2012 23:45:00 +0100 Subject: [PATCH] Fix bug in get_indexes affecting the tests --- django/db/backends/mysql/introspection.py | 1 + django/db/backends/postgresql_psycopg2/introspection.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py index 93e89c1263..477478ca9d 100644 --- a/django/db/backends/mysql/introspection.py +++ b/django/db/backends/mysql/introspection.py @@ -103,6 +103,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): continue if row[4] not in indexes: indexes[row[4]] = {'primary_key': False, 'unique': False} + # It's possible to have the unique and PK constraints in separate indexes. if row[2] == 'PRIMARY': indexes[row[4]]['primary_key'] = True if not bool(row[1]): diff --git a/django/db/backends/postgresql_psycopg2/introspection.py b/django/db/backends/postgresql_psycopg2/introspection.py index 5a29932859..d43b95406c 100644 --- a/django/db/backends/postgresql_psycopg2/introspection.py +++ b/django/db/backends/postgresql_psycopg2/introspection.py @@ -86,7 +86,13 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): # Here, we skip any indexes across multiple fields. if ' ' in row[1]: continue - indexes[row[0]] = {'primary_key': row[3], 'unique': row[2]} + if row[0] not in indexes: + indexes[row[0]] = {'primary_key': False, 'unique': False} + # It's possible to have the unique and PK constraints in separate indexes. + if row[3]: + indexes[row[0]]['primary_key'] = True + if row[2]: + indexes[row[0]]['unique'] = True return indexes def get_constraints(self, cursor, table_name):