Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update get_constraints with better comments

  • Loading branch information...
commit 77028194415cb03b1ff2a85a86d806a0366bccff 1 parent d5a7a3d
Andrew Godwin authored August 10, 2013
17  django/db/backends/__init__.py
@@ -1328,9 +1328,20 @@ def get_indexes(self, cursor, table_name):
1328 1328
 
1329 1329
     def get_constraints(self, cursor, table_name):
1330 1330
         """
1331  
-        Returns {'cnname': {'columns': set(columns), 'primary_key': bool, 'unique': bool}}
1332  
-        
1333  
-        Both single- and multi-column constraints are introspected.
  1331
+        Retrieves any constraints or keys (unique, pk, fk, check, index)
  1332
+        across one or more columns.
  1333
+
  1334
+        Returns a dict mapping constraint names to their attributes,
  1335
+        where attributes is a dict with keys:
  1336
+         * columns: List of columns this covers
  1337
+         * primary_key: True if primary key, False otherwise
  1338
+         * unique: True if this is a unique constraint, False otherwise
  1339
+         * foreign_key: (table, column) of target, or None
  1340
+         * check: True if check constraint, False otherwise
  1341
+         * index: True if index, False otherwise.
  1342
+
  1343
+        Some backends may return special constraint names that don't exist
  1344
+        if they don't name constraints of a certain type (e.g. SQLite)
1334 1345
         """
1335 1346
         raise NotImplementedError
1336 1347
 
4  django/db/backends/postgresql_psycopg2/introspection.py
@@ -169,7 +169,7 @@ def get_constraints(self, cursor, table_name):
169 169
                     "columns": [],
170 170
                     "primary_key": False,
171 171
                     "unique": False,
172  
-                    "foreign_key": False,
  172
+                    "foreign_key": None,
173 173
                     "check": True,
174 174
                     "index": False,
175 175
                 }
@@ -197,7 +197,7 @@ def get_constraints(self, cursor, table_name):
197 197
                     "columns": list(columns),
198 198
                     "primary_key": primary,
199 199
                     "unique": unique,
200  
-                    "foreign_key": False,
  200
+                    "foreign_key": None,
201 201
                     "check": False,
202 202
                     "index": True,
203 203
                 }

0 notes on commit 7702819

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