Commits

and...@69d324d9-c39d-4fdc-8679-7745eae9e2c8  committed 280c8d9

Make the unique_together detector do it Right for FKs

  • Participants
  • Parent commits 171f8ea

Comments (0)

Files changed (1)

File south/management/commands/startmigration.py

             model = model_unkey(mkey)
             print " + Added unique_together for [%s] on %s." % (", ".join(ut), model._meta.object_name)
             
+            cols = [get_field_column(model, f) for f in ut]
+            
             forwards += CREATE_UNIQUE_SNIPPET % (
                 ", ".join(ut),
                 model._meta.object_name,
                 model._meta.db_table,
-                ut,
+                cols,
             )
             
             backwards += DELETE_UNIQUE_SNIPPET % (
                 ", ".join(ut),
                 model._meta.object_name,
                 model._meta.db_table,
-                ut,
+                cols,
             )
         
         
     return added_models, deleted_models, added_fields, deleted_fields, changed_fields
 
 
+### Used to work out what columns any fields affect ###
+
+def get_field_column(model, field_name):
+    return model._meta.get_field_by_name(field_name)[0].column
+
+
 ### Creates SQL snippets for various common operations