"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:
CREATE TABLE IF NOT EXISTS `erp`.`je_menus` (
...
`create_date` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
...
)
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:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3