From e1bded65a2ca22f5d5e470370b5739b37b8dd2c6 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 3 Jun 2016 16:34:28 +0800 Subject: [PATCH] fix bug for "duplicate key name" when db init During the first init process for creating tables, if one field marked True for both "unique" and "search_index" , table creation will be failed. for example : create table `tabItem Barcode` ( name varchar(140) not null primary key, creation datetime(6), modified datetime(6), modified_by varchar(140), owner varchar(140), docstatus int(1) not null default '0', parent varchar(140), parentfield varchar(140), parenttype varchar(140), idx int(8) not null default '0', `item_barcode` varchar(140) unique, `sku_id` varchar(140), `unit_qty` varchar(140), `_comments` text, `_assign` text, `_liked_by` text, `store` varchar(140), `retail_price` varchar(140), `_user_tags` text, `uom` varchar(140), index `item_barcode`(`item_barcode`), index parent(parent)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci --- frappe/model/db_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index d71bff45a4..62f0643904 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -190,7 +190,7 @@ class DbTable: def get_index_definitions(self): ret = [] for key, col in self.columns.items(): - if col.set_index and col.fieldtype in type_map and \ + if col.set_index and not col.unique and col.fieldtype in type_map and \ type_map.get(col.fieldtype)[0] not in ('text', 'longtext'): ret.append('index `' + key + '`(`' + key + '`)') return ret