這兩天碰到的狀況是,資料是 MySQL 時,日期時間的比對 (__year / __month) 失效了。仔細看過文件以後,才發現 MySQL 需要事先設定,使用 mysql_tzinfo_to_sql 載入時區表格才行。
This function performs time zone conversions directly in the database. As a consequence, your database must be able to interpret the value of tzinfo.tzname(None). This translates into the following requirements:在終端機 (shell) 裡,輸入下列指令:
- SQLite: no requirements. Conversions are performed in Python with pytz (installed when you install Django).
- PostgreSQL: no requirements (see Time Zones).
- Oracle: no requirements (see Choosing a Time Zone File).
- MySQL: load the time zone tables with mysql_tzinfo_to_sql.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
接著重新啟動 MySQL 伺服器即可。mysql_tzinfo_to_sql 的用法不只一種,我選擇的是最簡單的用法。
沒有留言:
張貼留言