下面的代码为源代码,使用flask_migrate对数据库进行生成迁移操作。并且经历过了MySQL与PostgreSQL的测试……(艰难)
status_choices = [
(0, 'start'),
(1, 'end')
]
task_status = db.Column(ChoiceType(status_choices, db.Integer()), default=0)
在对表query时却发现始终会出现KeyError('0'),最终在轮子里print发现迁移的时候,即使是ChoiceType里面声明该字段是整数,数据库中的字段类型是'varchar(255)',具体表现为搜寻时在‘site-packages/sqlalchemy_utils/types/choice.py’下面ChoiceTypeTml索引时也是采用的字符串类型进行搜寻,在process_result_value方法里面print一下就能看到了,这个整数声明如果用这个迁移工具就是个搞笑的存在吗……
class ChoiceTypeImpl:
"""The implementation for the ``Choice`` usage."""
def __init__(self, choices):
if not choices:
raise ImproperlyConfigured(
'ChoiceType needs