Skip to content

Commit

Permalink
Compatible with tag notNull
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Oct 9, 2020
1 parent 7faf1ca commit 3d84695
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions tests/default_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down

0 comments on commit 3d84695

Please sign in to comment.