前言
习惯加前言了~~~~做什么都想着有前因后果什么的~~~~~~~
想着自己不能咸鱼,然后顺着友情链接逛博客的时候发现一位大佬刚发了一份Hitokoto(一言)的源码(还有数据,这才是重点)……
然后就开始设计起了一言用的数据表……
然后就噔的一下提示错误了:Invalid default value for ‘date’
解决方法
网上百度了好多教程,都是用什么命令什么命令,将什么命令改成什么命令………
噗,我用的是GUI………
后来才在Stack Overflow里面找到一个人的回复:
Interestingly, both these work:
start_time
timestamp(6),
And:
start_time
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
You can use the latter — leave the precision specifier out of the definition.But the right method is:
start_time
timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
As explained in the documentation:If a TIMESTAMP or DATETIME column definition includes an explicit fractional seconds precision value anywhere, the same value must be used throughout the column definition. This is permitted:
CREATE TABLE t1 (
ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)
);
This is not permitted:
CREATE TABLE t1 (
ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(3)
);
噗,此处省略三升血。
原来是因为字段长度和CURRENT_TIMESTAMP
长度不一致啊
解决方法1:字段和CURRENT_TIMESTAMP
都不设置长度
解决方法2:字段和CURRENT_TIMESTAMP
都设置相同的长度6(TIMESTAMP最长为6)
问题到此,已解决