Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion RuntimeWarning "DateTimeField received a naive datetime" with TIMESTAMP MySQL field

Received: by 10.101.175.32 with SMTP id c32mr949900anp.8.1353088286244;
        Fri, 16 Nov 2012 09:51:26 -0800 (PST)
X-BeenThere: django-users@googlegroups.com
Received: by 10.49.52.4 with SMTP id p4ls1072000qeo.45.gmail; Fri, 16 Nov 2012
 09:50:53 -0800 (PST)
Received: by 10.49.51.42 with SMTP id h10mr1150916qeo.42.1353088253464;
        Fri, 16 Nov 2012 09:50:53 -0800 (PST)
Date: Fri, 16 Nov 2012 09:50:53 -0800 (PST)
From: Sencha <mich...@d3i.com>
To: django-users@googlegroups.com
Message-Id: <2536b724-5ea3-4e50-956d-e3c15dd86164@googlegroups.com>
In-Reply-To: <1409af74-6cc3-4812-a835-6d9e95547b3c@googlegroups.com>
References: <52320100-2ea6-4aef-b33f-46ad8104e49d@googlegroups.com>
 <1409af74-6cc3-4812-a835-6d9e95547b3c@googlegroups.com>
Subject: Re: RuntimeWarning "DateTimeField received a naive datetime" with
 TIMESTAMP MySQL field
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_300_30869039.1353088253136"

------=_Part_300_30869039.1353088253136
Content-Type: multipart/alternative; 
	boundary="----=_Part_301_30869239.1353088253136"

------=_Part_301_30869239.1353088253136
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Yes I'm aware of this, however I'm not generating the datetime objects, 
it's all coming from Django (hence me wondering whether or not it's a bug 
or not). All I need to do to replicate the bug is get the object from the 
db and then save is straight away; then warning appears.

Django abstracts away the difference between MySQL's datetime field and 
timestamp field, so it should work!


On Friday, 16 November 2012 17:31:44 UTC, Timster wrote:

> It's well-documented. Check out the Django documentation page on time 
> zones:
>
> https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/
>
> When time zone support is enabled, Django uses time-zone-aware datetime 
> objects. If your code creates datetime objects, they should be aware too. 
> In this mode, the example above becomes:
>
> import datetimefrom django.utils.timezone import utc
> now = datetime.datetime.utcnow().replace(tzinfo=utc)
>
>
------=_Part_301_30869239.1353088253136
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<div>Yes I'm aware of this, however I'm&nbsp;not generating the datetime ob=
jects, it's all coming from Django (hence me wondering whether or not it's =
a bug or not). All I need to do to replicate the bug is get the object from=
 the db and then save is straight away; then warning appears.</div><div><br=
></div><div>Django abstracts away the difference between MySQL's datetime f=
ield and timestamp field, so it should work!</div><div><br></div><div><br><=
/div><div>On Friday, 16 November 2012 17:31:44 UTC, Timster  wrote:<br></di=
v><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;">It's well-documented. Check =
out the Django documentation page on time zones:<div><br></div><div><a href=
=3D"https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/" target=3D=
"_blank">https://docs.djangoproject.<wbr>com/en/1.4/topics/i18n/<wbr>timezo=
nes/</a><br></div><div><br></div><div><p style=3D"margin-top:0.6em;margin-b=
ottom:0.8em;color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:12px;=
line-height:16.78333282470703px">When time zone support is enabled, Django =
uses time-zone-aware datetime objects. If your code creates datetime object=
s, they should be aware too. In this mode, the example above becomes:</p><d=
iv style=3D"color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:12px;=
line-height:16.78333282470703px"><div><pre style=3D"font-size:medium;backgr=
ound-color:rgb(224,255,184);border-style:solid;border-color:rgb(148,218,58)=
;border-top-width:1px;border-bottom-width:1px;margin-top:1em;margin-bottom:=
1em;padding:0.3em 0.4em;overflow:auto"><span>import</span> <span style=3D"c=
olor:rgb(85,85,85)">datetime</span>
<span>from</span> <span style=3D"color:rgb(85,85,85)">django.utils.timezone=
</span> <span>import</span> <span>utc</span>

<span>now</span> <span style=3D"font-weight:bold">=3D</span> <span>datetime=
</span><span style=3D"font-weight:bold">.</span><span>datetime</span><span =
style=3D"font-weight:bold">.</span><span>utcnow</span><span>()</span><span =
style=3D"font-weight:bold">.</span><span>rep<wbr>lace</span><span>(</span><=
span>tzinfo</span><span style=3D"font-weight:bold">=3D</span><span>utc</spa=
n><span>)</span></pre></div></div></div></blockquote>
------=_Part_301_30869239.1353088253136--

------=_Part_300_30869039.1353088253136--