Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed get_indexes() hook from [2346] to return 'primary_key' instea…
…d of 'keyname'

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2348 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Feb 18, 2006
1 parent 27b41fd commit 5710c6e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions django/core/db/backends/mysql.py
Expand Up @@ -139,13 +139,13 @@ def get_indexes(cursor, table_name):
"""
Returns a dictionary of fieldname -> infodict for the given table,
where each infodict is in the format:
{'keyname': 'name of key',
{'primary_key': boolean representing whether it's the primary key,
'unique': boolean representing whether it's a unique index}
"""
cursor.execute("SHOW INDEX FROM %s" % DatabaseWrapper().quote_name(table_name))
indexes = {}
for row in cursor.fetchall():
indexes[row[4]] = {'keyname': row[2], 'unique': not bool(row[1])}
indexes[row[4]] = {'primary_key': (row[2] == 'PRIMARY'), 'unique': not bool(row[1])}
return indexes

OPERATOR_MAPPING = {
Expand Down
2 changes: 1 addition & 1 deletion django/core/management.py
Expand Up @@ -636,7 +636,7 @@ def table2model(table_name):
# Add primary_key and unique, if necessary.
column_name = extra_params.get('db_column', att_name)
if column_name in indexes:
if indexes[column_name]['keyname'] == 'PRIMARY':
if indexes[column_name]['primary_key']:
extra_params['primary_key'] = True
elif indexes[column_name]['unique']:
extra_params['unique'] = True
Expand Down

0 comments on commit 5710c6e

Please sign in to comment.