关于 mysql unsupported Scan, storing driver.Value type []uint8 into type *time.Time 的问题

背景:

查询 报错如下:

项目是go 项目,我使用的是gorm 

Scan error on column index 7, name "apply_time": unsupported Scan, storing driver.Value type []uint8 into type *time.Time

 

模型:

type ToolIpTelApply struct {
Id              string     `json:"id" gorm:"column:id" gorm:"primaryKey"`
BizCode         string     `json:"bizcode" gorm:"column:biz_code"`
EngName         string     `json:"eng_name" gorm:"column:eng_name"`
Status          int        `json:"status" gorm:"column:status"`
Remark          string     `json:"remark" gorm:"column:remark"`
Approver        string     `json:"approver" gorm:"column:approver"`
Allocationmsg   string     `json:"allocation_msg" gorm:"column:allocation_msg"`
ApplyTime       *time.Time `json:"apply_time" gorm:"column:apply_time"`
ApprovalTime    *time.Time `json:"approval_time" gorm:"column:approval_time"`
BusNumber       string     `json:"bus_number" gorm:"column:bus_number"`
IpTelNumber     string     `json:"ip_tel_number" gorm:"column:ip_tel_number"`
Building        string     `json:"building" gorm:"column:building"`
Floor           string     `json:"floor" gorm:"column:floor"`
Mac             string     `json:"mac" gorm:"column:mac"`
OldMac          string     `json:"old_mac" gorm:"column:old_mac"`
MacType         string     `json:"mac_type" gorm:"column:mac_type"`
OldIpTelNumber  string     `json:"old_ip_tel_number" gorm:"column:old_ip_tel_number"`
Area            string     `json:"area" gorm:"column:area"`
Workplaceid     int        `json:"workplaceid" gorm:"column:workplaceid"`
Workplacename   string     `json:"workplacename" gorm:"column:workplacename"`
ApprovalOpinion string     `json:"approval_opinion" gorm:"column:approval_opinion"`
}

 

数据库DDL

CREATE TABLE `tool_iptel_apply` (
`id` varchar(191) NOT NULL,
`biz_code` longtext,
`eng_name` longtext,
`status` bigint(20) DEFAULT NULL,
`remark` longtext,
`approver` longtext,
`allocation_msg` longtext,
`apply_time` datetime(3) DEFAULT NULL,  //  申请时间
`approval_time` datetime(3) DEFAULT NULL, // 审批时间
`ip_tel_number` longtext,
`building` longtext,
`floor` longtext,
`mac` longtext,
`mac_type` longtext,
`old_ip_tel_number` longtext,
`area` longtext,
`workplaceid` int(20) DEFAULT NULL,
`workplacename` longtext,
`approval_opinion` longtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

 

原有分析:

原有查找

技术分享图片

gorm 官方网站 查询 说明如下

技术分享图片

解决方案:

数据库连的时候增加配置

&parseTime=true

 

拓展:

注意:想要正确的处理 time.Time ,您需要带上 parseTime 参数, (更多参数) 要支持完整的 UTF-8 编码,您需要将 charset=utf8 更改为 charset=utf8mb4 查看 此文章 获取详情

关于 mysql unsupported Scan, storing driver.Value type []uint8 into type *time.Time 的问题

原文:https://www.cnblogs.com/zexin88/p/15308068.html

以上是关于 mysql unsupported Scan, storing driver.Value type []uint8 into type *time.Time 的问题的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>