Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 当前时间戳不起作用_Mysql - Fatal编程技术网

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 
);