Is Django corrupting timezone-aware DateTimeField when saving it to the Database?

前端 未结 3 1742
耶瑟儿~
耶瑟儿~ 2021-01-16 08:08

I have a Django model as described here

I create and save an instance of this model:

>>> from django.db.models import Max, F, Func
>>&         


        
3条回答
  •  执念已碎
    2021-01-16 08:49

    Yes. Some of the data is discarded.

    Django DateTime field stored data in a database DateTime storage that lacks timezone information thus the information is removed before storage.

    This is whet the manual says:

    Note that if you set this to point to a DateTimeField, only the date portion of the > field will be considered. Besides, when USE_TZ is True, the check will be performed > in the current time zone at the time the object gets saved.

    The proper way to store full datetime date would be to use a DateTimeOffset field - that can be found in MS-Sql and others. But this is not supported (yet?)

提交回复
热议问题