I have model with DateTimeField column.
I'm try to insert row with database current_time value directly into table by sql query.
My sql query for MySQL database like:
INSERT INTO MyTable (..., my_datetime, ...) VALUES (..., current_time, ...)
And get:
RuntimeWarning: DateTimeField ModelName.field_name received a naive datetime (2014-01-09 22:16:23) while time zone support is active.
How to insert current time directly into table by sql query without warning?
Use
django.utils.timezone.now
instead ofdatetime.datetime.now
.Further to falsetru's answer, if the datetime has already been created you can convert it to timezone aware:
You can also make the datetime time zone aware with
localize
frompytz
, as explained here.UTC:
Any other time zone:
And here the list of timezones.