id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
721	(patch) South sometimes tries to redo applied migrations	Dan Powell <dan.powell@…>	andrew	"Trying to redo applied migrations often results in errors such as {{{""django.db.utils.DatabaseError: index XYZ already exists.""}}}

This appears to happen because {{{south.migration.__init__.py(forwards, done)}}} directly compares migrations instances, and sometimes the instance of a migration class in 'forwards' and the instance of the same class in 'done' are different instances. Different instances of the same class do not compare as equal. One solution is to compare migration names.

Patch:
{{{
--- __init__.py.original	2011-02-10 16:53:56.000000000 +0000
+++ __init__.py	2011-02-11 11:12:45.000000000 +0000
@@ -20,10 +20,20 @@
 
 
 def to_apply(forwards, done):
-    return [m for m in forwards if m not in done]
+    return [m for m in forwards if not is_done(m, done)]
 
 def to_unapply(backwards, done):
-    return [m for m in backwards if m in done]
+    return [m for m in backwards if is_done(m, done)]
+    
+def is_done(migration, done):
+    """"""
+    Returns True if migration is done, i.e. applied.
+    Otherwise returns False.
+    
+    Compares migrations by name because different instances of the 
+    same migration class do not compare as equal.
+    """"""
+    return migration.name() in [m.name() for m in done]
 
 def problems(pending, done):
     last = None
}}}"	defect	closed	major	1.0	migrations	0.7.3	fixed	patch DatabaseError	
