From c3f52cee8b1e3d26fd0618399cc2a0cc012ff216 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 23 Jul 2020 23:56:13 +0800 Subject: [PATCH] Don't scan last insert id 0 --- callbacks/create.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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)