From 0d7e58ce79b4e38a63d12ce681f2a7e57191f56e Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 21 Jul 2019 16:23:31 +0200 Subject: [PATCH] Fix for #968 (database conversion fails for default strings under python2.7) --- cps/config_sql.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cps/config_sql.py b/cps/config_sql.py index 9fff7c21..809e97d8 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -271,8 +271,15 @@ def _migrate_table(session, orm_class): session.query(column).first() except exc.OperationalError as err: log.debug("%s: %s", column_name, err) + if column.default is not None: + if sys.version_info < (3, 0): + if isinstance(column.default.arg,unicode): + column.default.arg = column.default.arg.encode('utf-8') column_default = "" if column.default is None else ("DEFAULT %r" % column.default.arg) - alter_table = "ALTER TABLE %s ADD COLUMN `%s` %s %s" % (orm_class.__tablename__, column_name, column.type, column_default) + alter_table = "ALTER TABLE %s ADD COLUMN `%s` %s %s" % (orm_class.__tablename__, + column_name, + column.type, + column_default) log.debug(alter_table) session.execute(alter_table) changed = True