浏览代码

fix: Check if index exists with specific key_name

version-14
Suraj Shetty 3 年前
父节点
当前提交
39031d18ed
共有 2 个文件被更改,包括 4 次插入4 次删除
  1. +3
    -3
      frappe/database/mariadb/schema.py
  2. +1
    -1
      frappe/database/schema.py

+ 3
- 3
frappe/database/mariadb/schema.py 查看文件

@@ -69,7 +69,7 @@ class MariaDBTable(DBTable):
if unique_constraint_changed and not col.unique: if unique_constraint_changed and not col.unique:
unique_index_record = frappe.db.sql(""" unique_index_record = frappe.db.sql("""
SHOW INDEX FROM `{0}` SHOW INDEX FROM `{0}`
WHERE Column_name=%s
WHERE Key_name=%s
AND Non_unique=0 AND Non_unique=0
""".format(self.table_name), (col.fieldname), as_dict=1) """.format(self.table_name), (col.fieldname), as_dict=1)
if unique_index_record: if unique_index_record:
@@ -79,9 +79,9 @@ class MariaDBTable(DBTable):
if index_constraint_changed and not col.set_index: if index_constraint_changed and not col.set_index:
index_record = frappe.db.sql(""" index_record = frappe.db.sql("""
SHOW INDEX FROM `{0}` SHOW INDEX FROM `{0}`
WHERE Column_name=%s
WHERE Key_name=%s
AND Non_unique=1 AND Non_unique=1
""".format(self.table_name), (col.fieldname), as_dict=1)
""".format(self.table_name), (col.fieldname + '_index'), as_dict=1)
if index_record: if index_record:
drop_index_query.append("DROP INDEX `{}`".format(index_record[0].Key_name)) drop_index_query.append("DROP INDEX `{}`".format(index_record[0].Key_name))




+ 1
- 1
frappe/database/schema.py 查看文件

@@ -230,7 +230,7 @@ class DbColumn:
self.table.set_default.append(self) self.table.set_default.append(self)


# index should be applied or dropped irrespective of type change # index should be applied or dropped irrespective of type change
if ((current_def['index'] and not self.set_index and not self.unique)
if ((current_def['index'] and not self.set_index)
or (current_def['unique'] and not self.unique)): or (current_def['unique'] and not self.unique)):
# to drop unique you have to drop index # to drop unique you have to drop index
self.table.drop_index.append(self) self.table.drop_index.append(self)


正在加载...
取消
保存