for _, answer := range answers {
answer["pid"] = pid
fmt.Println(answer)
err := tx.Table(tablePaperQuestion).Create(&answer).Error
if err != nil {
fmt.Println("新建题目失败", err)
return 0, err
}
}
answers 是一个map切片,代码中的输出如下
map[answer:A blk_correct:0 blk_total:0 duration:120 id:22 is_correct:true is_pass:false is_sbj_question:false pid:3128078540406618 sbj_rate_score:-1 score:10 source:0 start_at:1672316400]
新建题目失败 Error 1062: Duplicate entry '0' for key 'PRIMARY'
表中主键为id,为啥似乎map中的id字段没有去对应表中的id字段,还是其它什么原因呢?为啥有上面这个报错啊