简体   繁体   中英

Django: USE_TZ = False is not updating Postgres database setting

So I have some confusion regarding Use_Tz in Django.

When the project was first started, USE_TZ was set to True, and we also had USE_I18N set to True.

However, last week it was decided to set these settings to False. According to the docs here , Postgresql should be able to switch between True and False automatically depending the settings.py file.

However, the date time fields in my tables show a timezone stamp of +01 at the end.

Also, when I go into the database directly, using the command \\d survey_server_app_activitylog , I see the following:

 date_reg       | timestamp with time zone |           

All fields with date time show the same entry. But, I believe that they should be set as timestamp without time zone

So, what gives? Am I totally interpreting USE_TZ = False incorrectly? Do I need to manually set the columns in the postgres database?

See the section of the timezone documentation dealing specifically with PostgreSQL:

The PostgreSQL backend stores datetimes as timestamp with time zone . In practice, this means it converts datetimes from the connection's time zone to UTC on storage, and from UTC to the connection's time zone on retrieval.

As a consequence, if you're using PostgreSQL, you can switch between USE_TZ = False and USE_TZ = True freely. The database connection's time zone will be set to TIME_ZONE or UTC respectively, so that Django obtains correct datetimes in all cases. You don't need to perform any data conversions.

That answers your specific question about why the column type hasn't changed. It's not clear what problem this is actually presenting for you, so it's hard to give further advice. If you try to change the type of the column outside of Django I would not expect correct behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM