Should ignore error when parsing default value for time, close #5176
This commit is contained in:
		
							parent
							
								
									540b47571a
								
							
						
					
					
						commit
						0097b39a77
					
				| @ -260,8 +260,8 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { | |||||||
| 			field.DataType = Time | 			field.DataType = Time | ||||||
| 		} | 		} | ||||||
| 		if field.HasDefaultValue && !skipParseDefaultValue && field.DataType == Time { | 		if field.HasDefaultValue && !skipParseDefaultValue && field.DataType == Time { | ||||||
| 			if field.DefaultValueInterface, err = now.Parse(field.DefaultValue); err != nil { | 			if t, err := now.Parse(field.DefaultValue); err == nil { | ||||||
| 				schema.err = fmt.Errorf("failed to parse default value `%v` for field %v", field.DefaultValue, field.Name) | 				field.DefaultValueInterface = t | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	case reflect.Array, reflect.Slice: | 	case reflect.Array, reflect.Slice: | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ require ( | |||||||
| 	gorm.io/driver/postgres v1.3.1 | 	gorm.io/driver/postgres v1.3.1 | ||||||
| 	gorm.io/driver/sqlite v1.3.1 | 	gorm.io/driver/sqlite v1.3.1 | ||||||
| 	gorm.io/driver/sqlserver 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 => ../ | replace gorm.io/gorm => ../ | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ func TestPostgres(t *testing.T) { | |||||||
| 		Name      string         `gorm:"check:name_checker,name <> ''"` | 		Name      string         `gorm:"check:name_checker,name <> ''"` | ||||||
| 		Test      uuid.UUID      `gorm:"type:uuid;not null;default:gen_random_uuid()"` | 		Test      uuid.UUID      `gorm:"type:uuid;not null;default:gen_random_uuid()"` | ||||||
| 		CreatedAt time.Time      `gorm:"type:TIMESTAMP WITHOUT TIME ZONE"` | 		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[]"` | 		Things    pq.StringArray `gorm:"type:text[]"` | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu