Scan error on column index 1, name “created_at”
提示:
Scan error on column index 1, name “created_at”: unsupported Scan, storing driver.Value type []uint8
打開數(shù)據(jù)庫(kù)的時(shí)候加上parseTime=true
root:123456@tcp(127.0.0.1:3306)/mapdb?charset=utf8parseTime=true
補(bǔ)充:golang Gorm 的使用總結(jié)
func (CoinLog) TableName() string { return "coin_log" }
ID int64 `gorm:"column:id" json:"id"`
通過預(yù)加載可以實(shí)現(xiàn)各個(gè)模型之間的一對(duì)多關(guān)系,例如下面的代碼,其中device結(jié)構(gòu)體對(duì)應(yīng)多個(gè)DeviceModular,DeviceModular又有多個(gè)CommWeimaqi
db.SqlDB.Preload("DeviceModular", "modular_type=1").Preload("DeviceModular.CommWeimaqi").Find(device)
gorm暫時(shí)不支持批量插入
tx := db.SqlDB.Begin() sqlStr := "INSERT INTO report_form (id,create_time,choose_count, device_fall_count,game_order_count,coin_count,member_count," + "day_member_count,visit_count,lgz_coin_count,weimaqi_coin_count,store_id,real_coin_count,m_coin_count,coin_spec) VALUES " vals := []interface{}{} const rowSQL = "(?,?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?)" var inserts []string for _, elem := range reportForms { inserts = append(inserts, rowSQL) vals = append(vals, elem.ID, elem.CreateTime, elem.ChooseCount, elem.DeviceFallCount, elem.GameOrderCount, elem.CoinCount, elem.MemberCount, elem.DayMemberCount, elem.VisitCount, elem.LgzCoinCount, elem.WeimaqiCoinCount, elem.StoreId, elem.RealCoinCount, elem.MCoinCount, elem.CoinSpec) } sqlStr = sqlStr + strings.Join(inserts, ",") err := tx.Exec(sqlStr, vals...).Error if err != nil { tx.Rollback() fmt.Print(err) }else { tx.Commit() }
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
標(biāo)簽:雞西 銅川 汕頭 梅河口 欽州 吐魯番 重慶 蘭州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《解決Go gorm踩過的坑》,本文關(guān)鍵詞 解決,gorm,踩過,的,坑,解決,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。