From 3d846957cd57c1660233ce7e0f6c56f21a030ccf Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 9 Oct 2020 17:39:35 +0800 Subject: [PATCH] Compatible with tag notNull --- schema/field.go | 2 ++ tests/default_value_test.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/schema/field.go b/schema/field.go index db516c33..e7f5b708 100644 --- a/schema/field.go +++ b/schema/field.go @@ -170,6 +170,8 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { if val, ok := field.TagSettings["NOT NULL"]; ok && utils.CheckTruth(val) { field.NotNull = true + } else if val, ok := field.TagSettings["NOTNULL"]; ok && utils.CheckTruth(val) { + field.NotNull = true } if val, ok := field.TagSettings["UNIQUE"]; ok && utils.CheckTruth(val) { diff --git a/tests/default_value_test.go b/tests/default_value_test.go index aa4a511a..14a0a977 100644 --- a/tests/default_value_test.go +++ b/tests/default_value_test.go @@ -10,9 +10,9 @@ func TestDefaultValue(t *testing.T) { type Harumph struct { gorm.Model Email string `gorm:"not null;index:,unique"` - Name string `gorm:"not null;default:foo"` + Name string `gorm:"notNull;default:foo"` Name2 string `gorm:"size:233;not null;default:'foo'"` - Name3 string `gorm:"size:233;not null;default:''"` + Name3 string `gorm:"size:233;notNull;default:''"` Age int `gorm:"default:18"` Enabled bool `gorm:"default:true"` }