diff --git a/callbacks/create.go b/callbacks/create.go index 707b94c1..c86cefe4 100644 --- a/callbacks/create.go +++ b/callbacks/create.go @@ -78,7 +78,9 @@ func Create(config *Config) func(db *gorm.DB) { } } case reflect.Struct: - db.Statement.Schema.PrioritizedPrimaryField.Set(db.Statement.ReflectValue, insertID) + if insertID > 0 { + db.Statement.Schema.PrioritizedPrimaryField.Set(db.Statement.ReflectValue, insertID) + } } } else { db.AddError(err)