Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add DATETIME columns to MySQL table

I'm trying to add two DATETIME columns to my User_Accounts table.

I create the columns in MySQL workbench like so: DATETIME(6)

What am I doing wrong?

like image 236
credo56 Avatar asked May 31 '15 20:05

credo56


People also ask

How to store date time in MySQL?

MySQL comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS.

What is the data type for time in MySQL?

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.

What is default value for DATETIME in MySQL?

DATETIME has a default of NULL unless defined with the NOT NULL attribute, in which case the default is 0.


1 Answers

Remove that size specifier (6) from your ALTER statement.

   ALTER TABLE `Chessmates`.`User_Accounts` 
    CHANGE COLUMN `Country` `Country` TEXT(25) NOT NULL ,
    ADD COLUMN `created_at` DATETIME NOT NULL AFTER `salt`,
    ADD COLUMN `updated_at` DATETIME NULL DEFAULT NULL AFTER `created_at`
like image 63
Rahul Avatar answered Sep 30 '22 03:09

Rahul