douluogu8713 2019-08-27 20:11
浏览 68

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?

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 用三极管设计—个共射极放大电路
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示