diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py index 0cdccbad16bc4..07cf22a317ba5 100644 --- a/django/core/cache/backends/db.py +++ b/django/core/cache/backends/db.py @@ -81,7 +81,8 @@ def delete(self, key): def has_key(self, key): now = datetime.now().replace(microsecond=0) cursor = connection.cursor() - cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % self._table, [key, now]) + cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % self._table, + [key, connection.ops.value_to_db_datetime(now)]) return cursor.fetchone() is not None def _cull(self, cursor, now):