mirror of https://github.com/go-gorm/gorm.git
Allow use NULL as default value for string, close #3363
This commit is contained in:
parent
680dda2c15
commit
dbe0f4d8d7
|
@ -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, "'")
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue