Home >Database >Mysql Tutorial >How to Fix MySQL Error #1292: 'Incorrect date value: '0000-00-00''?

How to Fix MySQL Error #1292: 'Incorrect date value: '0000-00-00''?

DDD
DDDOriginal
2024-12-22 16:41:11695browse

How to Fix MySQL Error #1292:

MySQL Error: "Incorrect date value: '0000-00-00'"

Problem

When attempting to insert a date value of '0000-00-00' into a column with a MySQL date type, the following error occurs:

#1292 - Incorrect date value: '0000-00-00'

Cause

This error is likely caused by strict mode being enabled in the MySQL database. In MySQL 5.7 and later versions, strict mode is enabled by default and enforces stricter validation rules for data integrity. One of these rules is that date values cannot be '0000-00-00'.

Solution

To resolve this issue, disable strict mode using the following query:

SET GLOBAL sql_mode = '';

This query removes all strict mode settings, including the validation rule that prevents '0000-00-00' from being inserted as a date value.

Additional Information

MySQL's strict mode provides additional data integrity checks, but it can also make it more difficult to work with certain types of data. If you do not require strict validation, it is recommended to disable strict mode to prevent this error from occurring.

For more information on strict mode in MySQL, refer to the official MySQL documentation.

The above is the detailed content of How to Fix MySQL Error #1292: 'Incorrect date value: '0000-00-00''?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn