From 342bc9f13d5d2b56bbd24cfdd5353cd5a3d7e56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 15 Jan 2019 11:30:20 +0100 Subject: [PATCH] Correctly rename column with SQLite The table must be recreated if the target column does not exist. Also temporary column name should use double underscore as module may use single underscore. issue7978 review52591002 --- trytond/backend/sqlite/table.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/trytond/backend/sqlite/table.py b/trytond/backend/sqlite/table.py index 929912235d..aba8b22425 100644 --- a/trytond/backend/sqlite/table.py +++ b/trytond/backend/sqlite/table.py @@ -93,7 +93,7 @@ class TableHandler(TableHandlerInterface): transaction = Transaction() database = transaction.database cursor = transaction.connection.cursor() - temp_table = '_temp_%s' % self.table_name + temp_table = '__temp_%s' % self.table_name TableHandler.table_rename(self.table_name, temp_table) new_table = TableHandler(self._model, history=self.history) columns, old_columns = [], [] @@ -116,7 +116,7 @@ class TableHandler(TableHandlerInterface): def column_rename(self, old_name, new_name): if self.column_exist(old_name): - if self.column_exist(new_name): + if not self.column_exist(new_name): self._recreate_table({old_name: {'name': new_name}}) else: logger.warning( @@ -322,7 +322,7 @@ class TableHandler(TableHandlerInterface): transaction = Transaction() database = transaction.database cursor = transaction.connection.cursor() - temp_table = '_temp_%s' % self.table_name + temp_table = '__temp_%s' % self.table_name TableHandler.table_rename(self.table_name, temp_table) new_table = TableHandler(self._model, history=self.history) for name, values in self._columns.items():