简体   繁体   中英

MySQL Error : Invalid default value for 'CREATED_DATE'

I have created an LAMP instance in AWS and while creating DB, I am stuck with this error

Error Code: 1067. Invalid default value for 'CREATED_DATE'

I checked sql mode and here is the response

 mysql>  SHOW VARIABLES LIKE 'sql_mode';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_mode      |       |
+---------------+-------+

1 row in set (0.00 sec)

I am not sure whey this is happening. Here is my db script

CREATE TABLE ENTITIES (
  ENTITY_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  NAME VARCHAR(30) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
  CREATED_DATE DATETIME DEFAULT CURRENT_TIMESTAMP,   
  UPDATED_DATE DATETIME ON UPDATE CURRENT_TIMESTAMP,     
  INDEX idx_ENTITIES_id1 (ENTITY_ID ASC)
) 
ENGINE = InnoDB
AUTO_INCREMENT=100
;

Any idea on how to fix this?

Change CREATED_DATE DATETIME DEFAULT CURRENT_TIMESTAMP

to

CREATED_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP

The problem is not because of Amazon EC2 instance.

Amazon EC2 is virtual machine similar to your own local machine.

The error is due to mistake in mysql query you are using, refer the create table mysql query syntax corresponding to the mysql version you have installed in the Amazon EC2 instance.

Hope it will solve the issue.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM