[patch] [fiel data] new patch p07_update_file_data_2
diff --git a/patches/april_2013/p05_update_file_data.py b/patches/april_2013/p05_update_file_data.py
index d387741..a5d2f7a 100644
--- a/patches/april_2013/p05_update_file_data.py
+++ b/patches/april_2013/p05_update_file_data.py
@@ -8,7 +8,7 @@
 	singles = get_single_doctypes()
 	
 	for doctype in webnotes.conn.sql_list("""select parent from tabDocField where 
-		fieldname='file_list' and fieldtype='Text'"""):
+		fieldname='file_list'"""):
 		update_file_list(doctype, singles)
 		
 		webnotes.conn.sql("""delete from tabDocField where fieldname='file_list'
@@ -32,9 +32,11 @@
 				ifnull(file_list, '')!=''""" % doctype, as_dict=True):
 				update_for_doc(doctype, doc)
 			webnotes.conn.commit()
-			webnotes.conn.sql("""alter table `tab%s` drop column file_list""" % doctype)
+			webnotes.conn.sql("""alter table `tab%s` drop column `file_list`""" % doctype)
 		except Exception, e:
-			if e.args[0]!=1054: raise e
+			print webnotes.getTraceback()
+			if (e.args and e.args[0]!=1054) or not e.args:
+				raise e
 
 def update_for_doc(doctype, doc):
 	for filedata in doc.file_list.split("\n"):
@@ -60,10 +62,14 @@
 					fd.doc.attached_to_name = doc.name
 					fd.save()
 				else:
-					fd = webnotes.bean("File Data", copy=fd.doclist)
-					fd.doc.attached_to_doctype = doctype
-					fd.doc.attached_to_name = doc.name
-					fd.insert()
+					try:
+						fd = webnotes.bean("File Data", copy=fd.doclist)
+						fd.doc.attached_to_doctype = doctype
+						fd.doc.attached_to_name = doc.name
+						fd.doc.name = None
+						fd.insert()
+					except webnotes.DuplicateEntryError:
+						pass
 		else:
 			webnotes.conn.sql("""delete from `tabFile Data` where name=%s""",
 				fileid)
\ No newline at end of file
diff --git a/patches/april_2013/p07_update_file_data_2.py b/patches/april_2013/p07_update_file_data_2.py
new file mode 100644
index 0000000..7b89a9d
--- /dev/null
+++ b/patches/april_2013/p07_update_file_data_2.py
@@ -0,0 +1,15 @@
+import webnotes
+def execute():
+	from patches.april_2013.p05_update_file_data import update_file_list, get_single_doctypes
+	
+	singles = get_single_doctypes()
+	for doctype in webnotes.conn.sql_list("""select table_name from `information_schema`.`columns`
+		where table_schema=%s and column_name='file_list'""", webnotes.conn.cur_db_name):
+			doctype = doctype[3:]
+			update_file_list(doctype, singles)
+			
+			webnotes.conn.sql("""delete from `tabCustom Field` where fieldname='file_list'
+				and parent=%s""", doctype)
+			webnotes.conn.sql("""delete from `tabDocField` where fieldname='file_list'
+				and parent=%s""", doctype)
+	
\ No newline at end of file
diff --git a/patches/april_2013/p07_update_file_data_custom_field.py b/patches/april_2013/p07_update_file_data_custom_field.py
deleted file mode 100644
index 909df05..0000000
--- a/patches/april_2013/p07_update_file_data_custom_field.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import webnotes
-def execute():
-	from patches.april_2013.p05_update_file_data import update_file_list, get_single_doctypes
-	singles = get_single_doctypes()
-	for doctype in webnotes.conn.sql("""select parent from `tabCustom Field` where 
-		fieldname='file_list' and fieldtype='Text'"""):
-			update_file_list(doctype, singles)
-			
-			webnotes.conn.sql("""delete from `tabCustom Field` where fieldname='file_list'
-					and parent=%s""", doctype)
-	
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 096fec80..70aeb4a 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -247,5 +247,5 @@
     "execute:webnotes.reload_doc('Stock', 'DocType', 'Delivery Note Item')",
 	"patches.april_2013.p06_default_cost_center",
 	"execute:webnotes.reset_perms('File Data')",
-	"patches.april_2013.p07_update_file_data_custom_field",
+	"patches.april_2013.p07_update_file_data_2",
 ]
\ No newline at end of file