Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

current_timeStamp is not working

Tags:

mysql

I tried this code

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

but the following error will come

1067 - Invalid default value for 'createdDate'

thanks

like image 489
A.C.Manikandan Avatar asked Sep 25 '22 15:09

A.C.Manikandan


1 Answers

Use simply CURRENT_TIMESTAMP instead CURRENT_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 DATETIME DEFAULT CURRENT_TIMESTAMP NOT NUll,
   updatedDate DATETIME 
);

In addition, you can initialize or update any TIMESTAMP column to the current date and time by assigning it a NULL value, unless it has been defined with the NULL attribute to permit NULL values.

For more knowledge click the link http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html

like image 147
Vipin Jain Avatar answered Oct 21 '22 22:10

Vipin Jain