看起来 GORM 不支持 DATE 类型,定义日期的唯一方法是通过 time.Time :
type Header struct {
Start time.Time `json:"period_start"`
End time.Time `json:"period_end" `
CreatedAt time.Time `json:"created_at" sql:"DEFAULT:CURRENT_TIMESTAMP"`
CreatedBy string `json:"created_by"`
UpdatedAt time.Time `json:"updated_at" sql:"DEFAULT:CURRENT_TIMESTAMP"`
UpdatedBy string `json:"updated_by"`
}
Run Code Online (Sandbox Code Playgroud)
因此创建的表将以 TIMESTAMP 作为类型。有没有解决的办法?我尝试了 sql:"DATE",但没有成功