登录
首页 >  Golang >  Go问答

如何解释这个错误信息呢? “目标不支持,应为切片或结构”

来源:stackoverflow

时间:2024-02-28 16:18:25 238浏览 收藏

欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《如何解释这个错误信息呢? “目标不支持,应为切片或结构”》,这篇文章主要讲到等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!

问题内容

我的结构是这样的:

type users struct{
  id uint 
  profile  *profile
  name string 
  profileid uint 
}
type profile struct{
  id uint 
  name string 
}

我想插入`user.profile1相关配置文件

db.first(&user.profile, user.profileid)

这里我得到这样的错误

unsupported destination, should be slice or struct

我不明白为什么会出现这个错误。我知道解决方案是创建配置文件切片,但我只需要一个配置文件。


解决方案


您尚未初始化 profile 结构。您必须首先初始化该结构。

user.Profile = &Profile{}
db.First(user.Profile, user.ProfileID)

今天关于《如何解释这个错误信息呢? “目标不支持,应为切片或结构”》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>