更新总数的时候报错:Column 'view_count' cannot be null

来源:11-5 电子书快照收集脚本编写-2

北7561604

2021-08-28

insert into ebook_snapshot(ebook_id, date, view_count, vote_count, view_increase, vote_increase)
select t1.id, curdate(), 0, 0, 0, 0
from ebook t1
where not exists(select 1
from ebook_snapshot t2
where t1.id = t2.ebook_id
and t2.date = curdate())
[2021-08-28 21:03:31] completed in 165 ms
hswiki> insert into ebook_snapshot(ebook_id, date, view_count, vote_count, view_increase, vote_increase)
select t1.id, curdate(), 0, 0, 0, 0
from ebook t1
where not exists(select 1
from ebook_snapshot t2
where t1.id = t2.ebook_id
and t2.date = curdate())
[2021-08-28 21:04:18] completed in 160 ms
hswiki> update ebook_snapshot t1, ebook t2
set t1.view_count = t2.view_count,
t1.vote_count = t2.vote_count
where t1.date = curdate()
and t1.ebook_id = t2.id
[2021-08-28 21:04:25] [23000][1048] Column ‘view_count’ cannot be null
[2021-08-28 21:04:26] [23000][1048] Column ‘view_count’ cannot be null

图片描述

写回答

3回答

weixin_慕斯卡0160118

2022-07-05

代码上是在docService里面插入新记录时,设置viewCount为0,这样避免genSnapshot方法将ebook表的null值来设置snapshot表。

但如果之前的ebook表里面有代码修改之前生成的数据,那么需要手动的修改ebook表里view_count, vote_count null值为0.

0
0

水深不语

2021-10-15

请问你是怎么解决的,我也有这个问题,在提交记录里;也没找到解决办法

0
0

甲蛙

2021-08-29

后面有讲到,在docService里,insert之前,给viewCount赋值0

0
1
水深不语
老师,能说一下具体的章节吗,我在提交纪录里没有找到您说的解决方法
2021-10-15
共1条回复

Spring Boot+Vue3前后端分离,实战wiki知识库系统

一课掌握前后端最火框架,更有职场竞争力

2524 学习 · 1671 问题

查看课程