0
goでormを使用して操作insertを実行しようとしています。go ormでNOT NULL制約が失敗しました
私は、フィールドのような時間型の値に値を代入挿入しないでください:NOT NULL constraint failed: topic.reply_time
:それはエラーがスローされます
ReplyTime time.Time `orm:"index"`
。
この値をnull値またはデフォルト値に設定するにはどうすればよいですか?
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
}
ありがとうございます。私は "time"型について混乱しています。nullableをサポートしているのでしょうか、単にこの "orm:"インデックス "' "を値に追加しているからです。 – machinezhou