From b5c30fd18c948214582727d70a83c350277daf20 Mon Sep 17 00:00:00 2001 From: Zhibin Dong Date: Wed, 26 May 2021 09:41:58 +0800 Subject: [PATCH] Tag default is in conflict with tag autoincrement --- schema/schema.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/schema/schema.go b/schema/schema.go index 1ce88fa5..13d357bb 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -210,13 +210,15 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error) if field := schema.PrioritizedPrimaryField; field != nil { switch field.GORMDataType { case Int, Uint: - if _, ok := field.TagSettings["AUTOINCREMENT"]; !ok { - if !field.HasDefaultValue || field.DefaultValueInterface != nil { - schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field) - } + if _, ok := field.TagSettings["DEFAULT"]; !ok { + if _, ok := field.TagSettings["AUTOINCREMENT"]; !ok { + if !field.HasDefaultValue || field.DefaultValueInterface != nil { + schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field) + } - field.HasDefaultValue = true - field.AutoIncrement = true + field.HasDefaultValue = true + field.AutoIncrement = true + } } } }