Compatible with tag notNull

This commit is contained in:
Jinzhu 2020-10-09 17:39:35 +08:00
parent 7faf1ca80f
commit 3d846957cd
2 changed files with 4 additions and 2 deletions

View File

@ -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) {

View File

@ -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"`
}