diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 76073c7..76d2838 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -62,6 +62,13 @@ class Command(NoArgsCommand):
                 if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name) or column_name != att_name:
                     extra_params['db_column'] = column_name
 
+                # Add primary_key and unique, if necessary.
+                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
+
                 # Modify the field name to make it Python-compatible.
                 if ' ' in att_name:
                     att_name = att_name.replace(' ', '_')
@@ -88,13 +95,6 @@ class Command(NoArgsCommand):
                     extra_params.update(field_params)
                     comment_notes.extend(field_notes)
 
-                    # Add primary_key and unique, if necessary.
-                    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 += '('
                     
                 if keyword.iskeyword(att_name):
diff --git a/tests/regressiontests/inspectdb/models.py b/tests/regressiontests/inspectdb/models.py
index fc2548b..fac47aa 100644
--- a/tests/regressiontests/inspectdb/models.py
+++ b/tests/regressiontests/inspectdb/models.py
@@ -6,3 +6,12 @@ class People(models.Model):
 
 class Message(models.Model):
     from_field = models.ForeignKey(People, db_column='from_id')
+
+class PeopleData(models.Model):
+    people_pk = models.ForeignKey(People, primary_key=True)
+    ssn = models.CharField(max_length=11)
+
+class PeopleMoreData(models.Model):
+    people_unique = models.ForeignKey(People, unique=True)
+    license = models.CharField(max_length=255)
+
diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py
index 683e6e9..e2eced5 100644
--- a/tests/regressiontests/inspectdb/tests.py
+++ b/tests/regressiontests/inspectdb/tests.py
@@ -13,4 +13,8 @@ class InspectDBTestCase(TestCase):
         error_message = "inspectdb generated an attribute name which is a python keyword"
         self.assertNotIn("from = models.ForeignKey(InspectdbPeople)", out.getvalue(), msg=error_message)
         self.assertIn("from_field = models.ForeignKey(InspectdbPeople)", out.getvalue())
+        self.assertIn("people_pk = models.ForeignKey(InspectdbPeople, primary_key=True)",
+            out.getvalue())
+        self.assertIn("people_unique = models.ForeignKey(InspectdbPeople, unique=True)",
+            out.getvalue())
         out.close()
