MySQL 日期导入问题
MySQL date import issue
我有以下 MySQL 数据库 table:
+---------------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------------+-------------+------+-----+---------+-------+
| fixtureid | int(11) | NO | PRI | NULL | |
| fixturedate | datetime | YES | | NULL | |
我想从 xmlsoccer.com 网站提取一些数据,但返回的格式为“2015-08-01T11:45:00+00:00”。
当我尝试导入它时出现以下错误:
Exception Type: ValueError Exception Value: MySQL backend does not
support timezone-aware datetimes when USE_TZ is False.
我的django代码如下:
fixtureUpdate = StraightredFixture(fixtureid=fixture['Id'],
away_team_id = fixture['AwayTeam_Id'],
home_team_id = fixture['HomeTeam_Id'],
fixturedate = fixture['Date'])
fixtureUpdate.save()
如果有人能给我指明正确的方向,让约会 MySQL 变得友好,那就太好了。非常感谢,艾伦
正如错误消息指出的那样,您应该:
- 通过设置
USE_TZ = True
启用时区支持
- 在将日期保存到数据库之前从日期中删除时区部分
我有以下 MySQL 数据库 table:
+---------------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------------+-------------+------+-----+---------+-------+
| fixtureid | int(11) | NO | PRI | NULL | |
| fixturedate | datetime | YES | | NULL | |
我想从 xmlsoccer.com 网站提取一些数据,但返回的格式为“2015-08-01T11:45:00+00:00”。
当我尝试导入它时出现以下错误:
Exception Type: ValueError Exception Value: MySQL backend does not support timezone-aware datetimes when USE_TZ is False.
我的django代码如下:
fixtureUpdate = StraightredFixture(fixtureid=fixture['Id'],
away_team_id = fixture['AwayTeam_Id'],
home_team_id = fixture['HomeTeam_Id'],
fixturedate = fixture['Date'])
fixtureUpdate.save()
如果有人能给我指明正确的方向,让约会 MySQL 变得友好,那就太好了。非常感谢,艾伦
正如错误消息指出的那样,您应该:
- 通过设置
USE_TZ = True
启用时区支持
- 在将日期保存到数据库之前从日期中删除时区部分