zoukankan      html  css  js  c++  java
  • 关于 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 查看 此文章 获取详情

  • 相关阅读:
    查询Python支持的.whl格式
    内置模块之os
    内置标准库之time
    迭代器(iterator)
    STM32F103和SIM800L打造低成本短信转发系统(五):控制程序
    STM32F103和SIM800L打造低成本短信转发系统(四):MDK-ARM
    STM32F103和SIM800L打造低成本短信转发系统(三):STM32CubeMX
    STM32F103和SIM800L打造低成本短信转发系统(二):软件安装篇
    STM32F103和SIM800L打造低成本短信转发系统(一):硬件篇
    处理SIM800L模块的时间字符串之URL编码(百分号编码)
  • 原文地址:https://www.cnblogs.com/zexin88/p/15308068.html
Copyright © 2011-2022 走看看