fix: Check if index exists with specific key_name
This commit is contained in:
parent
b3f9e8e2cf
commit
39031d18ed
2 changed files with 4 additions and 4 deletions
|
|
@ -69,7 +69,7 @@ class MariaDBTable(DBTable):
|
|||
if unique_constraint_changed and not col.unique:
|
||||
unique_index_record = frappe.db.sql("""
|
||||
SHOW INDEX FROM `{0}`
|
||||
WHERE Column_name=%s
|
||||
WHERE Key_name=%s
|
||||
AND Non_unique=0
|
||||
""".format(self.table_name), (col.fieldname), as_dict=1)
|
||||
if unique_index_record:
|
||||
|
|
@ -79,9 +79,9 @@ class MariaDBTable(DBTable):
|
|||
if index_constraint_changed and not col.set_index:
|
||||
index_record = frappe.db.sql("""
|
||||
SHOW INDEX FROM `{0}`
|
||||
WHERE Column_name=%s
|
||||
WHERE Key_name=%s
|
||||
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:
|
||||
drop_index_query.append("DROP INDEX `{}`".format(index_record[0].Key_name))
|
||||
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ class DbColumn:
|
|||
self.table.set_default.append(self)
|
||||
|
||||
# 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)):
|
||||
# to drop unique you have to drop index
|
||||
self.table.drop_index.append(self)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue