Index: django/core/management/commands/inspectdb.py
===================================================================
--- django/core/management/commands/inspectdb.py	(revision 8349)
+++ django/core/management/commands/inspectdb.py	(working copy)
@@ -45,6 +45,13 @@
                 comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
                 extra_params = {}  # Holds Field parameters such as 'db_column'.
 
+                # Add primary_key and unique, if necessary.
+                if att_name in indexes:
+                    if indexes[att_name]['primary_key']:
+                        extra_params['primary_key'] = True
+                    elif indexes[att_name]['unique']:
+                        extra_params['unique'] = True
+
                 if ' ' in att_name:
                     extra_params['db_column'] = att_name
                     att_name = att_name.replace(' ', '')
@@ -82,14 +89,6 @@
                         extra_params['max_digits'] = row[4]
                         extra_params['decimal_places'] = row[5]
 
-                    # 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]['primary_key']:
-                            extra_params['primary_key'] = True
-                        elif indexes[column_name]['unique']:
-                            extra_params['unique'] = True
-
                     field_type += '('
 
                 # Don't output 'id = meta.AutoField(primary_key=True)', because
