Avoid exception when changing fieldname from upper to lowercase (#2517)
This commit is contained in:
parent
9fac886ed8
commit
4b4ec8e01e
1 changed files with 6 additions and 4 deletions
|
|
@ -254,7 +254,7 @@ class DbTable:
|
|||
def get_columns_from_db(self):
|
||||
self.show_columns = frappe.db.sql("desc `%s`" % self.name)
|
||||
for c in self.show_columns:
|
||||
self.current_columns[c[0]] = {'name': c[0],
|
||||
self.current_columns[c[0].lower()] = {'name': c[0],
|
||||
'type':c[1], 'index':c[3]=="MUL", 'default':c[4], "unique":c[3]=="UNI"}
|
||||
|
||||
# GET foreign keys
|
||||
|
|
@ -290,7 +290,7 @@ class DbTable:
|
|||
|
||||
def alter(self):
|
||||
for col in self.columns.values():
|
||||
col.build_for_alter_table(self.current_columns.get(col.fieldname, None))
|
||||
col.build_for_alter_table(self.current_columns.get(col.fieldname.lower(), None))
|
||||
|
||||
query = []
|
||||
|
||||
|
|
@ -298,7 +298,8 @@ class DbTable:
|
|||
query.append("add column `{}` {}".format(col.fieldname, col.get_definition()))
|
||||
|
||||
for col in self.change_type:
|
||||
query.append("change `{}` `{}` {}".format(col.fieldname, col.fieldname, col.get_definition()))
|
||||
current_def = self.current_columns.get(col.fieldname.lower(), None)
|
||||
query.append("change `{}` `{}` {}".format(current_def["name"], col.fieldname, col.get_definition()))
|
||||
|
||||
for col in self.add_index:
|
||||
# if index key not exists
|
||||
|
|
@ -395,7 +396,8 @@ class DbColumn:
|
|||
return
|
||||
|
||||
# type
|
||||
if (current_def['type'] != column_def) or \
|
||||
if (current_def['type'] != column_def) or\
|
||||
self.fieldname != current_def['name'] or\
|
||||
((self.unique and not current_def['unique']) and column_def not in ('text', 'longtext')):
|
||||
self.table.change_type.append(self)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue