Reputation: 17869
So I have a script that is creating some models in my database, and I used datetime
rather than timezone
. It does not give me an error, but I get the following warning:
/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/db/models/fields/__init__.py:903: RuntimeWarning: DateTimeField Notification.date_sent received a naive datetime (2014-01-17 16:20:56.524827) while time zone support is active.
RuntimeWarning)
My question here is: does it make a difference? sure maybe I should be using timezone
because users can be in different timezones, but then why is it giving me a RuntimeWarning
? Is there a major difference in efficiency?
Upvotes: 1
Views: 588
Reputation: 122506
It's not about efficiency but about correctness. As the error says, your datetime is naive which means the timezone of that datetime is not known. This means that other parts of your application are not able to display / convert it properly as they can't interpret the timezone it is in.
As the documentation says:
A naive object does not contain enough information to unambiguously locate itself relative to other date/time objects. Whether a naive object represents Coordinated Universal Time (UTC), local time, or time in some other timezone is purely up to the program, just like it’s up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand and to work with, at the cost of ignoring some aspects of reality.
Upvotes: 2