Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用timestamp类型查询的时候报错: unsupported Scan, storing driver.Value type []uint8 into type *time.Time #7202

Closed
LIANGQI0811 opened this issue Sep 22, 2024 · 1 comment
Assignees
Labels

Comments

@LIANGQI0811
Copy link

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:

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Sep 22, 2024
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants