怎么理解这个错误? "unsupported destination, should be slice or struct"
How understand this error? "unsupported destination, should be slice or struct"
我有这样的结构:
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)
我有这样的结构:
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)