Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved get_primary_key_column implementation to base

Refs #17574.
  • Loading branch information...
commit 09a99714c05316717d2797afd2e458dbf6aa880f 1 parent 3622be4
Claude Paroz authored September 08, 2012
7  django/db/backends/__init__.py
@@ -1034,9 +1034,12 @@ def get_key_columns(self, cursor, table_name):
1034 1034
 
1035 1035
     def get_primary_key_column(self, cursor, table_name):
1036 1036
         """
1037  
-        Backends can override this to return the column name of the primary key for the given table.
  1037
+        Returns the name of the primary key column for the given table.
1038 1038
         """
1039  
-        raise NotImplementedError
  1039
+        for column in six.iteritems(self.get_indexes(cursor, table_name)):
  1040
+            if column[1]['primary_key']:
  1041
+                return column[0]
  1042
+        return None
1040 1043
 
1041 1044
     def get_indexes(self, cursor, table_name):
1042 1045
         """
10  django/db/backends/mysql/introspection.py
@@ -2,7 +2,6 @@
2 2
 from .base import FIELD_TYPE
3 3
 
4 4
 from django.db.backends import BaseDatabaseIntrospection
5  
-from django.utils import six
6 5
 
7 6
 
8 7
 foreign_key_re = re.compile(r"\sCONSTRAINT `[^`]*` FOREIGN KEY \(`([^`]*)`\) REFERENCES `([^`]*)` \(`([^`]*)`\)")
@@ -88,15 +87,6 @@ def get_key_columns(self, cursor, table_name):
88 87
         key_columns.extend(cursor.fetchall())
89 88
         return key_columns
90 89
 
91  
-    def get_primary_key_column(self, cursor, table_name):
92  
-        """
93  
-        Returns the name of the primary key column for the given table
94  
-        """
95  
-        for column in six.iteritems(self.get_indexes(cursor, table_name)):
96  
-            if column[1]['primary_key']:
97  
-                return column[0]
98  
-        return None
99  
-
100 90
     def get_indexes(self, cursor, table_name):
101 91
         cursor.execute("SHOW INDEX FROM %s" % self.connection.ops.quote_name(table_name))
102 92
         # Do a two-pass search for indexes: on first pass check which indexes

0 notes on commit 09a9971

Please sign in to comment.
Something went wrong with that request. Please try again.