4

I am working on a Django project with MySQL as the back-end, this warning keeps troubling me, can anyone please suggest a fix for this. Thanks in advance!!

/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808: 
    RuntimeWarning: DateTimeField received a naive datetime (2013-04-22 10:34:44) 
    while time zone support is active.
Serp C
  • 864
  • 1
  • 10
  • 24
Niranjan Sagar
  • 819
  • 1
  • 15
  • 17

1 Answers1

10

You have to make the following changes:

In settings.py, you need to add following line:

USE_TZ = True

Also, in your code you should create aware datetime objects:

eg:

Instead of

import datetime

now = datetime.datetime.now()

You should do:

from django.utils.timezone import now

now_time = now()

This will make use of USE_TZ from settings.py and will create aware datetime objects instead of native.

You should read https://docs.djangoproject.com/en/dev/topics/i18n/timezones/

Akshar Raaj
  • 14,231
  • 7
  • 51
  • 45