我有一个要缓存的昂贵查询,但我不断收到以下错误:
query = MyModel.objects.all().annotate(
max_time=Max(Case(When(m2mthrough__somebool=True,
then=F('m2mthrough__rel1__rel2__sometime')),
output_field=models.DateTimeField())),
for obj in query:
obj.cached_max_time = obj.max_time
obj.save()
...
RuntimeWarning: DateTimeField MyModel.cached_max_time received a naive datetime (2017-01-01 01:23:45) while time zone support is active.
我认为从数据库中提取的datetime字段始终知道时区。这是否与Case(When(...))
的使用有关,或者我是否确实在数据库中存储了一些不了解时区的日期?