Several tables in the mysql system schema exist to store time zone information . The MySQL installation procedure creates the time zone tables, but does not load them. To do so manually, use the following instructions.
Named time zones can be used only if the time zone information tables in the**mysql**database have been created and populated. Otherwise, use of a named time zone results in an error:
mysql> SET time_zone = 'UTC';
ERROR 1298 (HY000): Unknown or incorrect time zone: 'UTC'
我们从上面的粗体部分可以发现:之前之所以设置Asia/Shanghai不生效是因为**MySQL 仅当数据库中的时区信息表已创建并填充时,才能使用命名时区。**因为刚开始没有填充时区表,MySQL 不知道 Asia/Shanghai 代表什么意思,所以才会出错无法启动 MySQL 服务。
When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end user’s time zone in templates and forms.
换句话说,只要是项目使用时区支持,那么,无论你设置什么时区,Django 在数据库中存储数据默认都是使用 UTC 时间。所以,如果想要更改 Django 存储数据的时区,还需要在 setting 中的 DATABASES 里,将TIME_ZONE选项设置为你想要的时区。
更新了 Django 项目的配置,然后重新启动,进入 admin 界面,时间没问题,然后进入 MySQL shell 查看时间列,也没问题。终于,终于成功了!!!
Several tables in the mysql system schema exist to store time zone information . The MySQL installation procedure creates the time zone tables, but does not load them. To do so manually, use the following instructions.
Named time zones can be used only if the time zone information tables in the**mysql**database have been created and populated. Otherwise, use of a named time zone results in an error:
mysql> SET time_zone = 'UTC';
ERROR 1298 (HY000): Unknown or incorrect time zone: 'UTC'
我们从上面的粗体部分可以发现:之前之所以设置Asia/Shanghai不生效是因为**MySQL 仅当数据库中的时区信息表已创建并填充时,才能使用命名时区。**因为刚开始没有填充时区表,MySQL 不知道 Asia/Shanghai 代表什么意思,所以才会出错无法启动 MySQL 服务。
When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end user’s time zone in templates and forms.
换句话说,只要是项目使用时区支持,那么,无论你设置什么时区,Django 在数据库中存储数据默认都是使用 UTC 时间。所以,如果想要更改 Django 存储数据的时区,还需要在 setting 中的 DATABASES 里,将TIME_ZONE选项设置为你想要的时区。
更新了 Django 项目的配置,然后重新启动,进入 admin 界面,时间没问题,然后进入 MySQL shell 查看时间列,也没问题。终于,终于成功了!!!