0
我正嘗試使用orm執行操作插入。NOT NULL約束在go orm中失敗
我也插不值分配給像場時間類型值:
ReplyTime time.Time `orm:"index"`
它會拋出錯誤:NOT NULL constraint failed: topic.reply_time
。
那麼如何將此值設置爲可爲空或默認值?
type Topic struct {
Id int64
UId int64
Title string
Content string `orm:"size(5000)"`
Attachment string
Created time.Time `orm:"index"`
Updated time.Time `orm:"index"`
Views int64 `orm:"index"`
Author string
ReplyTime time.Time `orm:"index"`
ReplyCount int64
ReplyLastUserId int64
}
func AddTopic(title, content string) error {
o := orm.NewOrm()
t := time.Now()
topic := &Topic{Title:title, Content:content, Created:t, Updated:t}
_, err := o.Insert(topic)
return err
}
感謝您的幫助。我對「時間」類型感到困惑,它支持可爲空還是僅僅因爲我將該「orm:」索引「'」添加到值中。 – machinezhou