Commits

Andrew Godwin committed a4e7854

Fix SQLite primary key bug.

Comments (0)

Files changed (2)

docs/autodetector.rst

 
 If you change the ``unique=`` attribute on a field, or the ``unique_together``
 in a model's Meta, South will detect and change the constraints on the database
-accordingly (except on SQLite, where UNIQUE isn't supported, and just ignored.)
+accordingly (except on SQLite, where we don't get have the code to edit UNIQUE
+constraints).
 
 
 

south/db/sqlite3.py

         # Work out the (possibly new) definitions of each column
         definitions = {}
         cursor = self._get_connection().cursor()
+        # Get the index descriptions
+        indexes = self._get_connection().introspection.get_indexes(cursor, table_name)
+        # Work out new column defs.
         for column_info in self._get_connection().introspection.get_table_description(cursor, table_name):
             name = column_info[0]
             type = column_info[1]
+            unique = indexes[name]['unique']
+            primary_key = indexes[name]['primary_key']
             # Deal with an alter (these happen before renames)
             if name in altered:
                 type = altered[name]
                 name = renames[name]
             # Add to the defs
             definitions[name] = type
+            if primary_key:
+                definitions[name] += " PRIMARY KEY"
         # Alright, Make the table
         self.execute("CREATE TABLE %s (%s)" % (
             self.quote_name(temp_name),