gorm连接数据库,时间字段为0001-01-01T00:00:00Z

栏目: 数据库 · 发布时间: 7年前

今天被这个问题困挠了很久,用gorm连接数据库时,定义的时间字段总是空值 0001-01-01T00:00:00Z

本来一直以为是我 mysql 字段定义的问题。

但各种尝试无果后,在一个golang大神密布的群里弱弱的问了一下,

然后就一秒就获得了正确答案

原来是gorm在连接mysql时需要多传一个参数parseTime。

即:

db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")

defer db.Close()

这件事的感悟是。。。是坑总得踩。问题是google、baidu那么久,竟然没有命中正确答案。 那我就加一篇吧~~

标签:golang


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Elements of Statistical Learning

The Elements of Statistical Learning

Trevor Hastie、Robert Tibshirani、Jerome Friedman / Springer / 2009-10-1 / GBP 62.99

During the past decade there has been an explosion in computation and information technology. With it have come vast amounts of data in a variety of fields such as medicine, biology, finance, and mark......一起来看看 《The Elements of Statistical Learning》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

随机密码生成器
随机密码生成器

多种字符组合密码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试