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
二:解决方案:
结构体中默认为空的字段,添加 *

本文来自博客园,作者:Carver大脸猫,转载请注明原文链接:https://www.cnblogs.com/carver/articles/18124081

浙公网安备 33010602011771号