diff --git a/schema/field.go b/schema/field.go index 45ec66e1..96291816 100644 --- a/schema/field.go +++ b/schema/field.go @@ -260,8 +260,8 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { field.DataType = Time } if field.HasDefaultValue && !skipParseDefaultValue && field.DataType == Time { - if field.DefaultValueInterface, err = now.Parse(field.DefaultValue); err != nil { - schema.err = fmt.Errorf("failed to parse default value `%v` for field %v", field.DefaultValue, field.Name) + if t, err := now.Parse(field.DefaultValue); err == nil { + field.DefaultValueInterface = t } } case reflect.Array, reflect.Slice: diff --git a/tests/go.mod b/tests/go.mod index 9dfa26ff..17e5d350 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -14,7 +14,7 @@ require ( gorm.io/driver/postgres v1.3.1 gorm.io/driver/sqlite v1.3.1 gorm.io/driver/sqlserver v1.3.1 - gorm.io/gorm v1.23.1 + gorm.io/gorm v1.23.3 ) replace gorm.io/gorm => ../ diff --git a/tests/postgres_test.go b/tests/postgres_test.go index 418b713e..66b988c3 100644 --- a/tests/postgres_test.go +++ b/tests/postgres_test.go @@ -19,7 +19,7 @@ func TestPostgres(t *testing.T) { Name string `gorm:"check:name_checker,name <> ''"` Test uuid.UUID `gorm:"type:uuid;not null;default:gen_random_uuid()"` CreatedAt time.Time `gorm:"type:TIMESTAMP WITHOUT TIME ZONE"` - UpdatedAt time.Time `gorm:"type:TIMESTAMP WITHOUT TIME ZONE"` + UpdatedAt time.Time `gorm:"type:TIMESTAMP WITHOUT TIME ZONE;default:current_timestamp"` Things pq.StringArray `gorm:"type:text[]"` }