From e1084e78d0acea979520458ce16f2bc17141ba59 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 8 Jul 2020 18:50:49 +0800 Subject: [PATCH] Allow customize AutoIncrement for primary field --- schema/schema.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/schema/schema.go b/schema/schema.go index 72bc6544..b85bbd7e 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -187,8 +187,11 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error) if !field.HasDefaultValue || field.DefaultValueInterface != nil { schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field) } - field.HasDefaultValue = true - field.AutoIncrement = true + + if _, ok := field.TagSettings["AUTOINCREMENT"]; !ok { + field.HasDefaultValue = true + field.AutoIncrement = true + } } }