以下代码中,struct里 我需要做插入操作时,CreateAt 这个字段想让以数据库默认值的方式写入 如何设置?
import (
"fmt"
"github.com/astaxie/beego/orm"
)
type ProjectUsers struct {
Id int
ProjectId int
UserId int
Amount float64
StartedAt string
EarningAmount float64
Status int
BtcEarning float64
CreateAt string
}
func init() {
orm.RegisterModel(new(ProjectUsers))
}
// 写入
func InsertOrder(projectId,userId int,availableHours string, money float64) (int64, bool) {
o := orm.NewOrm()
var data ProjectUsers
data.ProjectId = projectId
data.UserId = userId
data.Amount = money
data.StartedAt = availableHours
resId,err := o.Insert(&data)
fmt.Println(err)
if err == nil && resId > 0{
return resId,true
}
return 0,false
}```
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…