Commits

charettes committed 2aca282

Now that `get_indexes()` consistently returns only unique and primary key
columns on all backends we can't assume all altered columns will be present
in the provided indexes dict.

Comments (0)

Files changed (1)

south/db/sqlite3.py

             type = column_info['type'].replace("PRIMARY KEY", "")
             # Add on primary key, not null or unique if needed.
             if (primary_key_override and primary_key_override == name) or \
-               (not primary_key_override and indexes[name]['primary_key']):
+               (not primary_key_override and name in indexes and
+                indexes[name]['primary_key']):
                 type += " PRIMARY KEY"
             elif not column_info['null_ok']:
                 type += " NOT NULL"
-            if indexes[name]['unique'] and name not in uniques_deleted:
+            if (name in indexes and indexes[name]['unique'] and
+                name not in uniques_deleted):
                 type += " UNIQUE"
             if column_info['dflt_value'] is not None:
                 type += " DEFAULT " + column_info['dflt_value']
         # Add on altered columns
         for name, type in altered.items():
             if (primary_key_override and primary_key_override == name) or \
-               (not primary_key_override and indexes[name]['primary_key']):
+               (not primary_key_override and name in indexes and
+                indexes[name]['primary_key']):
                 type += " PRIMARY KEY"
-            if indexes[name]['unique'] and name not in uniques_deleted:
+            if (name in indexes and indexes[name]['unique'] and
+                name not in uniques_deleted):
                 type += " UNIQUE"
             definitions[name] = type
         # Add on the new columns