[SQL] create table s7_note
(
id mediumint unsigned not null auto_increment comment 'Id',
title varchar(100) not null comment '标题',
content longtext not null comment '内容',
addtime datetime not null default current_timestamp comment '添加时间',
ip int not null comment 'IP地址',
primary key(id)
)engine=InnoDB default charset utf8 comment '留言表';
[Err] 1067 - Invalid default value for 'addtime'
逸先生2017-08-24 10:38:16
create table s7_note ( id mediumint unsigned not null auto_increment comment 'Id', title varchar(100) not null comment '标题', content longtext not null comment '内容', addtime datetime not null default '' comment '添加时间', ip int not null comment 'IP地址', primary key(id) )engine=InnoDB default charset utf8 comment '留言表';
#Just change the default value, the simplest way
天蓬老师2017-08-21 17:18:45
datetime and current_timestamp, theoretically, their values are the same. However, current_timestamp has an automatic conversion process when reading and writing, and the value ranges between them are also different. You can think of current_timestamp as a variable, because it needs to be converted when reading and writing. You can think of it as having a date() function that secretly formats it behind the scenes. At this point it becomes an expression.
It is recommended to upgrade. Or change a value or constant to initialize datetime.