zoukankan      html  css  js  c++  java
  • 解决Database returned an invalid datetime value. Are time zone definitions for your database installed?

    设定博客文章按照时间分层筛选出现问题

      ret=Article.objects.filter(user=user).annotate(month=TruncMonth("create_time")).values("month").annotate(c=Count("nid")).values_list("month","c")
      print("ret----->",ret)

    解决方案:

    修改settings.py中时区配置信息:

    # LANGUAGE_CODE = 'en-us'
    #
    # TIME_ZONE = 'Asia/Shanghai'
    #
    # USE_I18N = True
    #
    # USE_L10N = True
    #
    # USE_TZ = True
    
    # 解决Database returned an invalid datetime value. Are time zone definitions for your database installed?
    
    LANGUAGE_CODE = 'zh-hans'
    
    TIME_ZONE = 'Asia/Shanghai'
    
    USE_I18N = True
    
    USE_L10N = True

    注意问题:

    启用 USE_TZ = True 后,处理时间方面,有两条 “黄金法则”:
    保证存储到数据库中的是 UTC 时间;
    在函数之间传递时间参数时,确保时间已经转换成 UTC 时间;

  • 相关阅读:
    词云(WordCloud)
    Pandas常用方法
    PCA降维的原理及实现
    支持向量机(SVM)公式整理
    《小狗钱钱》
    初识 Netty
    hello world
    算法-归并排序
    算法-堆与堆排序
    Java并发编程05-线程池
  • 原文地址:https://www.cnblogs.com/xiao-apple36/p/10633459.html
Copyright © 2011-2022 走看看