Question

I have a new project in Django 1.4, using sqlite db. Also using django_extenstions' shell_plus with no problems.

When I installed IPython, both shell and shell_plus started to complain about:

/path/to/my/virtualenv/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:50:
RuntimeWarning: SQLite received a naive datetime (2012-07-29 13:15:45.229464) while time zone support is active.

It seems IPython itself uses unaware datetimes. How can this be fixed?

EDIT:

I don't want to disable Django's timezone support.

Was it helpful?

Solution

I put this in my local_settings.py:

#ignore the following error when using ipython:
#/django/db/backends/sqlite3/base.py:50: RuntimeWarning:
#SQLite received a naive datetime (2012-11-02 11:20:15.156506) while time zone support is active.

import warnings
import exceptions
warnings.filterwarnings("ignore", category=exceptions.RuntimeWarning, module='django.db.backends.sqlite3.base', lineno=53)

OTHER TIPS

I have the same issue but I don't think that it's really a problem. IPython seems to use naive datetimes internally and Django just warns about it. Django always sends this warning when you turn on timezone support and whenever it detects a naive datetime. On my machine, this warning only appears when I start or close IPython. This warning does not influence your work with IPython in any way. So you can safely create aware datetimes normally inside IPython and also save them to your database. In order to get rid of that warning, you probably would have to work on IPython's internals.

When working with aware datetimes in general, I strongly recommend to use pytz for this purpose.

modify settings.py, set USE_TZ to False would solve this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top