mysql "datetime NOT NULL DEFAULT '1970-01-01' " gets turned to 0000-00-00 00:00:00

veccy picture veccy · Sep 8, 2010 · Viewed 15.4k times · Source

I have a column created as

`date_start` datetime NOT NULL DEFAULT '1970-01-01'

However when I upload data from a CSV file with the LOAD DATA command with a blank entry for date_start the value saved is 0000-00-00 00:00:00 ?

Answer

Greg W picture Greg W · Sep 8, 2010

NULL and 'a blank entry' are not always treated the same in MySql. In the case of the datetime data type, blank entries are automatically converted to 0000-00-00 00:00:00. You can think of this as a form of typecasting, where a blank gets typecast to zero.

In your data file, try replacing all blank dates with the DEFAULT keyword.