From 2476c0fbb470e3ced8f61278da2bbdce1c24564c Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 26 Jun 2020 07:26:45 +0800 Subject: [PATCH] Set db type after autotime --- schema/field.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/schema/field.go b/schema/field.go index a8328367..f02968fa 100644 --- a/schema/field.go +++ b/schema/field.go @@ -223,15 +223,6 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { field.DataType = DataType(dataTyper.GormDataType()) } - if val, ok := field.TagSettings["TYPE"]; ok { - switch DataType(strings.ToLower(val)) { - case Bool, Int, Uint, Float, String, Time, Bytes: - field.DataType = DataType(strings.ToLower(val)) - default: - field.DataType = DataType(val) - } - } - if v, ok := field.TagSettings["AUTOCREATETIME"]; ok || (field.Name == "CreatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) { if strings.ToUpper(v) == "NANO" { field.AutoCreateTime = UnixNanosecond @@ -248,6 +239,15 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { } } + if val, ok := field.TagSettings["TYPE"]; ok { + switch DataType(strings.ToLower(val)) { + case Bool, Int, Uint, Float, String, Time, Bytes: + field.DataType = DataType(strings.ToLower(val)) + default: + field.DataType = DataType(val) + } + } + if field.Size == 0 { switch reflect.Indirect(fieldValue).Kind() { case reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.Float64: