Mysql 当前时间戳不起作用
我试过这个密码Mysql 当前时间戳不起作用,mysql,Mysql,我试过这个密码 CREATE TABLE users ( userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll, account VARCHAR(200) NOT NULL, password varchar(200) NOT Null, isActive varchar(10) NOT NUll, createdDate DATETIME DEFAULT CURRENT_TIMESTAMP() NOT N
CREATE TABLE users (
userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL,
password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate DATETIME DEFAULT CURRENT_TIMESTAMP() NOT NUll,
updatedDate DATETIME
);
但是下面的错误将会出现
1067-createdDate的默认值无效
谢谢将数据类型
datetime
更改为timestamp
,它会工作的
CREATE TABLE users ( userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL,
password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate **timestamp** DEFAULT CURRENT_TIMESTAMP() NOT NUll,
updatedDate DATETIME )
只需使用
CURRENT\u TIMESTAMP
代替CURRENT\u TIMESTAMP()
此外,您可以初始化或更新任何时间戳列到
通过为当前日期和时间分配空值,除非
使用NULL属性定义以允许NULL值
要了解更多信息,请单击链接尝试此代码,它应该可以工作
CREATE TABLE users (
userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL,
password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate DATETIME DEFAULT CURRENT_TIMESTAMP NOT NUll,
updatedDate DATETIME
);
您正在使用的mysql版本可能存在重复?在5.6之前,仅允许
时间戳
数据类型。使用:createdDate
datetime在更新当前时间戳时默认为空,
CREATE TABLE users (
userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL,
password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate DATETIME DEFAULT CURRENT_TIMESTAMP NOT NUll,
updatedDate DATETIME
);