The best way current may be using Gorm hook, though we have to list all columns we need to ignore insert/update. GORM Hooks
In my case, I want to ignore insert field A if it is empty and B if it equals 0:
func (c C) BeforeCreate(tx *gorm.DB) (err error) {
if c.A == "" {
tx.Statement.Omits = append(tx.Statement.Omits, "a_column")
}
if c.B == "" {
tx.Statement.Omits = append(tx.Statement.Omits, "b_column")
}
return
}