Alter table error because the row has invalid data. Invalid datetime value: '0000-00-00 00:00:00'
I am updating the current user table with the following expression:
`ALTER TABLE `users` ADD `title` VARCHAR( 5 ) NULL DEFAULT NULL AFTER `surname` ;`
Returns the following error:
#1292 - Incorrect datetime value: '0000-00-00 00:00:00' for column 'created_at' at row 1
Created_at:
created_at datetime NOT NULL
Not sure why the data is not valid - could it be related to MySQL versions (5.5.43 to 5.1.73)?
The fix I have at the moment is to update the datetime value before the ALTER TABLE statement:
UPDATE `users` SET `created_at`='2014-01-01 00:00:00' WHERE `created_at`='0000-00-00 00:00:00';
Is this a smart decision?
source to share
MySQL docs say
The server requires the month and day values ββto be valid, not just in the range 1 to 12 and 1 to 31, respectively.
also:
When strict mode is enabled, invalid dates will generate an error. To allow such dates, enable ALLOW_INVALID_DATES.
So Michael - sqlbot asked you the right question.
source to share
you should disable STRICT_TRANS_TABLES mode
SET sql_mode = '';
or go to /etc/mysql/my.cnf
and comment outSTRICT_TRANS_TABLES
useful note SQL STRICT MODE
source to share