Loading

golang sql查询默认为空的字段报错 sql: Scan error on column index 6, name "user_account": converting NULL to string is unsupported

一:出现的问题如下:

row := db.QueryRow("select user_id,user_name,user_pwd,user_email,user_tel,user_token,user_account from carver_user_go where user_name = ?", userName)
err := row.Scan(&userInfo.UserId, &userInfo.UserName, &userInfo.UserPwd, &userInfo.UserEmail, &userInfo.UserTel, &userInfo.UserToken, &userInfo.UserAccount)
fmt.Println(err)

查询的报错为:sql: Scan error on column index 6, name "user_account": converting NULL to string is unsupported

二:解决方案:

结构体中默认为空的字段,添加 *

posted @ 2024-04-09 15:28  Carver大脸猫  阅读(70)  评论(0)    收藏  举报