I'm running into an issue with the use of the MySQL `TIMESTAMP` field 
compared to `DATETIME` field.

Django is run with timezone support and default timezone of `UTC`.

I have 2 fields in my MySQL table, one is type `DATETIME` and the other is 
`TIMESTAMP`. Both are set in the model as a `DateTimeField`. The data is 
already populated in this example.

When the data is loaded into the model by Django, I can see in the 
`DateTimeField`'s `get_prep_value` method that the `DATETIME` field value 
come through as:

datetime.datetime(2012, 11, 16, 16, 9, 25, tzinfo=<UTC>)


and the `TIMESTAMP` comes through as:

datetime.datetime(2012, 11, 16, 15, 51, 32)


So the value from the timestamp MySQL field is coming through not initiated 
with the default timezone like the datetime field is.

This becomes a problem with re-saving the model, even after making no 
changes. The warning is being thrown up:

File 
"/Users/me/.virtualenvs/momento/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
 
line 809, in get_prep_value RuntimeWarning)
RuntimeWarning: DateTimeField received a naive datetime (2012-11-16 
15:51:32) while time zone support is active.


Is this a bug? Any recommendations how to overcome this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/uPSy092r7fsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to