Your Question

my code like:


db := G.DB

if in.BrandId != 0 { 
    db = db.Where("`brand_id` = ?", in.BrandId)
}
if in.CategoryId != 0 { 
    db = db.Where("`parent_id` = ?", in.CategoryId)
}

var goods []MD.DocGoods
if err = db.Find(&goods).Error; err != nil {
    return
}

The SQL will be

SELECT * FROM `goods` WHERE `goods`.`deleted_at` IS NULL

But, there is an error : unsupported data type: 0xc000765780: Table not set, please set it like: db.Model(&user) or db.Table("users")

If I just use db.Find(&goods),it will be OK.

The document you expected this should be explained

Expected answer

I'm not sure if this error is a mistake

Comment From: li-jin-gou

hello @ancheGT can you provide a demo in https://github.com/go-gorm/playground?

Comment From: jinzhu

I guess its a usage issue, feel free to recreate another issue with reproducible demo

thank you.

Comment From: huangjingui

I also encountered this problem, the difference is because the model has more fields than the database table. Looking for a perfect solution

Comment From: DevJalax

Is this correct ? @huangjingui

Comment From: rohanchauhan02

I am also facing the same issue. Is there any solution available for this ??

Comment From: SombreCode

I am also facing the same issue. Is there any solution available for this ??

add gorm:"-" to struct

Comment From: KreanXie

for me,i just forget to add my new struct into AutoMigrate()

maybe you just forget db.AutoMigrate(model.YourModel{})