Saturday, November 17, 2012

Re: RuntimeWarning "DateTimeField received a naive datetime" with TIMESTAMP MySQL field

On Fri, 16 Nov 2012 08:25:52 -0800 (PST)
Sencha <michael@d3i.com> wrote:

> 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?

Yes and looks like you have fixed it. But I saw this with sqlite3 so does your fix fix that too?

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate