Fix for #968 (database conversion fails for default strings under python2.7)

This commit is contained in:
Ozzieisaacs 2019-07-21 16:23:31 +02:00
parent 3e008ef29b
commit 0d7e58ce79

View File

@ -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