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