From 7021db3655381405b8c3f848319a66128b96041b Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 22 Jul 2020 19:03:19 +0800 Subject: [PATCH] Fix FieldsWithDefaultDBValue for primary field, close #3187 --- schema/schema.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/schema/schema.go b/schema/schema.go index bcf65939..1106f0c5 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -184,11 +184,11 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error) if field := schema.PrioritizedPrimaryField; field != nil { switch field.GORMDataType { case Int, Uint: - if !field.HasDefaultValue || field.DefaultValueInterface != nil { - schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field) - } - if _, ok := field.TagSettings["AUTOINCREMENT"]; !ok { + if !field.HasDefaultValue || field.DefaultValueInterface != nil { + schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field) + } + field.HasDefaultValue = true field.AutoIncrement = true }