patternsqlModerate
Invalid default value for DateTime when changing to utf8_general_ci
Viewed 0 times
utf8_general_civaluedefaultforwhenchanginginvaliddatetime
Problem
I'm trying to run a script to modify a database, this query
gives this error
the column
Question: Is there a valid "invalid" default value that can replace
ALTER TABLE cmContentVersion CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;gives this error
ERROR 1067 (42000) at line 68: Invalid default value for 'modifiedDateTime'
Warning (Code 1264): Out of range value for column 'modifiedDateTime' at row 1
Error (Code 1067): Invalid default value for 'modifiedDateTime'the column
modifiedDateTime is defined as`modifiedDateTime` datetime NOT NULL default '0000-00-00 00:00:00',Question: Is there a valid "invalid" default value that can replace
0000-00-00 00:00:00 when using utf8_general_ci. Or do I have to tell the developers to stop relying on an "invalid date" in their code?Solution
This looks like more of a SQL mode issue than the char set. Strict mode (and more specifically NO_ZERO_DATE which is part of strict mode) usually sets off that error if the table was created with an all zero default date before turning on strict.
What we use (for similar modified date columns), is the '1970-01-01 00:00:01'.
and on a slightly related note, we use timestamp for these columns (and for created time too). Takes half the storage space, and is faster access.
What we use (for similar modified date columns), is the '1970-01-01 00:00:01'.
and on a slightly related note, we use timestamp for these columns (and for created time too). Takes half the storage space, and is faster access.
Context
StackExchange Database Administrators Q#6171, answer score: 15
Revisions (0)
No revisions yet.