我正在 Windows Azure 上部署我的 Django 项目。我使用 SQLite 作为数据库服务器,一切正常。部署我的项目后,我决定将其与 SQL Azure 数据库连接,但似乎此解决方案产生了一些错误。我无法再编辑用户资料。我总是得到这个错误:
AttributeError at /admin/auth/user/1/ 'unicode' object has no attribute 'tzinfo'
最佳答案
当您的数据库包含如下日期时间戳时会发生此错误:
0000-00-00 00:00:00.000000
(如果您使用 MySQLWorkbench 删除或覆盖以前的日期,这可能会在 MySQL 中发生)
当您尝试在 Django 模型对象中检索这些记录时,您会收到来自 pytz 的异常。时区库:
AttributeError 'unicode' object has no attribute 'tzinfo'
您应该先在数据库中编辑这些日期,并将它们设置为较新的日期,例如 2018-01-01 00:00:00.000000
或设置为 NULL
(但不是空白)。
参见:
另见:
关于django - 如何修复 Django 错误 : "' unicode' object has no attribute 'tzinfo' "on database read,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16492031/