"Invalid Default Value for 'create_date' Field: Understanding NO_ZERO_DATE SQL Mode"
In a recent SQL create statement, you encounter the error "'Invalid default value for 'create_date'" for the following SQL:
<code class="sql">CREATE TABLE IF NOT EXISTS `erp`.`je_menus` ( ... `create_date` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', ... ) </code>
To resolve this error, it's crucial to understand the MySQL SQL Mode, specifically the NO_ZERO_DATE setting. This setting disallows the use of '0000-00-00' as a valid date in strict mode. This occurs because SQL treats boolean values as numbers (e.g., TRUE = 1, FALSE = 0) and stores dates as integers representing the number of days since a reference point. Consequently, using '0000-00-00' conflicts with the '0' value used for boolean values.
To address this issue, consider the following options:
The above is the detailed content of Why Am I Getting \'Invalid Default Value for \'create_date\' Field\' in MySQL and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!