Golang-sqlboiler |中文 {“错误”:“模型:无法填充以下默认值:sql:结果集中没有行

I'm struggling with inserting some rows into my SQLite DB. I'm using SQLBoiler as my ORM library.

when I'm trying to execute the following code:

//CreateWeeklyForecastReport create a full week forecast report
func CreateWeeklyForecastReport(mock *dm.ForecastMock, storeNumber int, isDefault bool) (*models.FORECASTWEEKLY, error) {
    res := createNewForecastWeekly(storeNumber, isDefault)
    if err := res.Insert(context.Background(), DB, boil.Infer()); err != nil {
        return nil, err
    }
    ordersByDays := groupOrdersByDates(mock.DBData.OrdersTimes)
    for day, orderTime := range ordersByDays {
        daily := models.FORECASTDAILY{DATE: day, FORECASTWEEKLYS: res.FORECASTWID}
        if err := daily.Insert(context.Background(), DB, boil.Infer()); err != nil {
            return nil, err
        }
        mock.DBData.OrdersTimes = orderTime
        res := ForecastDaily(mock)
        for _, hr := range res {
            hourRes := hr.ToForecastHourly(daily.FORECASTDID)
            //CODE FAILS HERE
            if err := hourRes.Insert(context.Background(), DB, boil.Infer()); err != nil {
                return nil, err
            }
        }
    }
    return &res, nil
}

all of the inserts are working perfectly except for the last one. at the last insert:

 if err := hourRes.Insert(context.Background(), DB, boil.Infer()); err != nil {
    return nil, err
 }

and I'm getting the following error:

2019-08-27T22:50:55.387+0300    ERROR   infra/LogUtils.go:73    failed to create custom forecast report {"error": "models: unable to populate default values for FORECAST_HOURLY: sql: no rows in result set", "errorVerbose": "sql: no rows in result set
models: unable to populate default values for FORECAST_HOURLY
bitbucket.org/dragontailcom/analysis/models.

the funny part is that the row is actually inserted into the DB. enter image description here

Table definition: enter image description here

any ideas?

douqingzhi0980
douqingzhi0980 嘿,我以前读过。我的情况有点不同,我在插入后确实获得了正确的ID,并且如您所见,我以相同的方式在上面5行中插入值,而没有奇怪的错误。
大约一年之前 回复
doude2635
doude2635 我认为答案在这里:stackoverflow.com/questions/53507760/…
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问