Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update get_constraints with better comments
  • Loading branch information
andrewgodwin committed Aug 10, 2013
1 parent d5a7a3d commit 7702819
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions django/db/backends/__init__.py
Expand Up @@ -1328,9 +1328,20 @@ def get_indexes(self, cursor, table_name):

def get_constraints(self, cursor, table_name):
"""
Returns {'cnname': {'columns': set(columns), 'primary_key': bool, 'unique': bool}}
Both single- and multi-column constraints are introspected.
Retrieves any constraints or keys (unique, pk, fk, check, index)
across one or more columns.
Returns a dict mapping constraint names to their attributes,
where attributes is a dict with keys:
* columns: List of columns this covers
* primary_key: True if primary key, False otherwise
* unique: True if this is a unique constraint, False otherwise
* foreign_key: (table, column) of target, or None
* check: True if check constraint, False otherwise
* index: True if index, False otherwise.
Some backends may return special constraint names that don't exist
if they don't name constraints of a certain type (e.g. SQLite)
"""
raise NotImplementedError

Expand Down
4 changes: 2 additions & 2 deletions django/db/backends/postgresql_psycopg2/introspection.py
Expand Up @@ -169,7 +169,7 @@ def get_constraints(self, cursor, table_name):
"columns": [],
"primary_key": False,
"unique": False,
"foreign_key": False,
"foreign_key": None,
"check": True,
"index": False,
}
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_constraints(self, cursor, table_name):
"columns": list(columns),
"primary_key": primary,
"unique": unique,
"foreign_key": False,
"foreign_key": None,
"check": False,
"index": True,
}
Expand Down

0 comments on commit 7702819

Please sign in to comment.