diff --git a/schema/field.go b/schema/field.go index 2e649d81..b49b7de6 100644 --- a/schema/field.go +++ b/schema/field.go @@ -201,7 +201,7 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { case reflect.String: field.DataType = String isFunc := strings.Contains(field.DefaultValue, "(") && - strings.Contains(field.DefaultValue, ")") + strings.Contains(field.DefaultValue, ")") || strings.ToLower(field.DefaultValue) == "null" if field.HasDefaultValue && !isFunc { field.DefaultValue = strings.Trim(field.DefaultValue, "'") diff --git a/tests/default_value_test.go b/tests/default_value_test.go index aa4a511a..44309eab 100644 --- a/tests/default_value_test.go +++ b/tests/default_value_test.go @@ -13,6 +13,7 @@ func TestDefaultValue(t *testing.T) { Name string `gorm:"not null;default:foo"` Name2 string `gorm:"size:233;not null;default:'foo'"` Name3 string `gorm:"size:233;not null;default:''"` + Name4 string `gorm:"size:233;default:null"` Age int `gorm:"default:18"` Enabled bool `gorm:"default:true"` }