我将应用程序从sqlite3迁移到MYSQL:在迁移表文件发生更改后,最初TABLE字段在sqlite3中是bool类型(在mysql中bool为tinyint)。
Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/var/www/stacks/apps/PROJECT/apps/accounts/decorators.py" in inner_decorator
44. return func(request, *args, **kwargs)
File "/var/www/stacks/apps/PROJECT/apps/reports/views.py" in hiv_report_new
98. return form.get_itable(pk)
File "/var/www/stacks/apps/PROJECT/apps/reports/forms.py" in get_itable
665. data = cursor.execute(query)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py" in execute
34. return self.cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py" in execute
86. return self.cursor.execute(query, args)
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py" in execute
207. if not self._defer_warnings: self._warning_check()
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py" in _warning_check
117. warn(w[-1], self.Warning, 3)
Exception Type: Warning at /reports/
Exception Value: Truncated incorrect DOUBLE value: 'True'
答案 0 :(得分:1)
tinyint列不接受布尔值,将布尔值转换为整数:
intvalue = int(boolean_value)
分别为0
和1
存储False
或True
。
另一方面,0
和1
在布尔上下文中测试为false和true,因此您没有将它们转换回来。如果需要,您仍然可以使用bool()
。