From f4b823ae2df4a4e40100268d956d4b260623c16f Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 28 Aug 2014 14:43:49 +0530 Subject: [PATCH] [fix] [database.py] cleanup index size from name --- frappe/database.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frappe/database.py b/frappe/database.py index fe3c67929e..4f72cfdf6c 100644 --- a/frappe/database.py +++ b/frappe/database.py @@ -9,6 +9,7 @@ import MySQLdb import warnings import datetime import frappe +import re import frappe.model.meta from frappe.utils import now, get_datetime from frappe import _ @@ -536,10 +537,14 @@ class Database: def add_index(self, doctype, fields, index_name=None): if not index_name: index_name = "_".join(fields) + "_index" + + # remove index length if present e.g. (10) from index name + index_name = re.sub(r"\s*\([^)]+\)\s*", r"", index_name) + if not frappe.db.sql("""show index from `tab%s` where Key_name="%s" """ % (doctype, index_name)): frappe.db.commit() frappe.db.sql("""alter table `tab%s` - add index %s(%s)""" % (doctype, index_name, ", ".join(fields))) + add index `%s`(%s)""" % (doctype, index_name, ", ".join(fields))) def close(self): if self._conn: