8000 使用timestamp类型查询的时候报错: unsupported Scan, storing driver.Value type []uint8 into type *time.Time · Issue #7202 · go-gorm/gorm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
使用timestamp类型查询的时候报错: unsupported Scan, storing driver.Value type []uint8 into type *time.Time #7202
Closed as not planned
@LIANGQI0811

Description

@LIANGQI0811

GORM Playground Link

go-gorm/playground#1

Description

DDL如下:

CREATE TABLE `account` (
  `id` int NOT NULL AUTO_INCREMENT,
  `account` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `password` varchar(255) COLLATE utf8mb4_general_ci DEFAULT 'wang177',
  `is_enable` int DEFAULT '1',
  `level` int DEFAULT '1',
  `gad_level` int DEFAULT '0' COMMENT '神等级',
  `last_login` timestamp NULL DEFAULT '2000-01-01 00:00:00' COMMENT '最后登录时间',
  `today_active` int DEFAULT '0' COMMENT '今日活跃',
  `day7_active` int DEFAULT '0' COMMENT '7日活跃',
  `status` int DEFAULT '0' COMMENT '状态:暂时没有用',
  `shunyi_shi_num` int DEFAULT '0' COMMENT '瞬移浮石数量',
  `random_monster_num` int DEFAULT NULL COMMENT '随机卷轴数量',
  `hp_num` int DEFAULT NULL COMMENT '冰原生命药剂数量',
  `lasi_times` int DEFAULT '0' COMMENT '当日拉斯维加斯次数',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `unq_account` (`account`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

使用gen gorm生成dao和model

大致如下:

type Account struct {
	ID               int32     `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
	Account          string    `gorm:"column:account;not null" json:"account"`
	Password         string    `gorm:"column:password;default:wang177" json:"password"`
	IsEnable         int32     `gorm:"column:is_enable;default:1" json:"isEnable"`
	Level            int32     `gorm:"column:level;default:1" json:"level"`
	GadLevel         int32     `gorm:"column:gad_level;comment:神等级" json:"gadLevel"`                                  // 神等级
	LastLogin        time.Time `gorm:"column:last_login;default:2000-01-01 00:00:00;comment:最后登录时间" json:"lastLogin"` // 最后登录时间
	TodayActive      int32     `gorm:"column:today_active;comment:今日活跃" json:"todayActive"`                           // 今日活跃
	Day7Active       int32     `gorm:"column:day7_active;comment:7日活跃" json:"day7Active"`                             // 7日活跃
	Status           int32     `gorm:"column:status;comment:状态:暂时没有用" json:"status"`                                  // 状态:暂时没有用
	ShunyiShiNum     int32     `gorm:"column:shunyi_shi_num;comment:瞬移浮石数量" json:"shunyiShiNum"`                      // 瞬移浮石数量
	RandomMonsterNum int32     `gorm:"column:random_monster_num;comment:随机卷轴数量" json:"randomMonsterNum"`              // 随机卷轴数量
	HpNum            int32     `gorm:"column:hp_num;comment:冰原生命药剂数量" json:"hpNum"`                                   // 冰原生命药剂数量
	LasiTimes        int32     `gorm:"column:lasi_times;comment:当日拉斯维加斯次数" json:"lasiTimes"`                          // 当日拉斯维加斯次数
}

然后写如下语句

exist, err:= accountDo.Where(accountDo.Account.Eq(a.Account)).Where(accountDo.IsEnable.Eq(1)).First()

err = sql: Scan error on column index 6, name "last_login": unsupported Scan, storing driver.Value type []uint8 i
nto type *time.Time; sql: Scan error on column index 6, name "last_login": unsupported Scan, storing driver.Value type []uint8 into type *time.Time; sql: Scan error on column index 6, name "last_login": unsupported Scan, storing driver.Value type []uint8 into type *time.Time
Error acquiring lock:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0