When creating a table, a datetime error is reported. I don't know why?
元曦
元曦 2017-08-21 11:52:27
0
3
1458

[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'


元曦
元曦

reply all(3)
逸先生
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

Peter_Zhu

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.

Peter_Zhu

Please upgrade to MySQL 5.6+

  • reply Is there no other alternative?
    元曦 author 2017-08-21 14:14:07
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template