5

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?

2
  • I can see how adding a not null column without default value would fail if the table already has data, but I would expect a different error message. Still, you could try giving it a default value. I think create time and update time can be automatically entered by MySQL. -edit- Yes, see auto-initializing timestamps (It is for timestamps, not datetime).
    – GolezTrol
    May 31, 2015 at 20:49
  • added the full error log
    – credo56
    May 31, 2015 at 20:51

1 Answer 1

9

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`
3
  • 1
    This worked, but why? MySQL workbench provides DATETIME() as a datatype, not DATETIME.
    – credo56
    May 31, 2015 at 20:56
  • Check MySQL documentation dev.mysql.com/doc/refman/5.6/en/datetime.html for more information.
    – Rahul
    May 31, 2015 at 20:58
  • 1
    DATETIME(6) seems to of worked for me. It is only available in MySQL 5.7 and later . The number inside the brackets represents the amount of decimal places the fractional seconds can use ( microseconds ). DATETIME eg 2016-06-05 02:07:48 DATETIME(6) eg 2016-06-05 02:07:48.123456 Jun 14, 2016 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.