jaysonpryde
jaysonpryde

Reputation: 2813

Django: Timezone stored in MySQL DB is not correct

I have an application which is using 'Asia/Taipei' as its timezone in settings.py and using the auto_now=true on one of the datetimefield on models.py:

--- settings.py ---
TIME_ZONE = 'Asia/Taipei'
--- models.py ---
models.DateTimeField(auto_now=True)

On my system, Taipei is also used as my timezone: enter image description here

On the MySQL Workbench, I already queried for both global and session tz and their returns are "SYSTEM": enter image description here

My question is when an entry is added to DB, the timezone specified on the system and on settings.py was not used. See sample snapshot: enter image description here

What am I lacking? Doing wrong? Thanks in advance!

Upvotes: 3

Views: 4661

Answers (2)

Siva Arunachalam
Siva Arunachalam

Reputation: 7760

Typically, database will store the UTC time by default and the corresponding application will do the conversion based on the settings/configurations.

In your case, it depends on your USE_TZ setting.

When USE_TZ is False, this is the time zone in which Django will store all datetimes. When USE_TZ is True, this is the default time zone that Django will use to display datetimes in templates and to interpret datetimes entered in forms.

For more details, you can refer

Upvotes: 6

jaysonpryde
jaysonpryde

Reputation: 2813

it's working now. I just set USE_TZ = False

Upvotes: 4

Related Questions