Home > Database > Mysql Tutorial > body text

Why am I getting the \'Field Doesn\'t Have Default Value\' error in MySQL STRICT Mode?

Susan Sarandon
Release: 2024-11-05 12:40:02
Original
916 people have browsed it

Why am I getting the

MySQL STRICT Mode Error: 1364 'Field Doesn't Have Default Value'

In a recent migration from MAMP to Apache, MySQL, and PHP, performing INSERT commands suddenly resulted in the following error:

SQLSTATE[HY000]: General error: 1364 Field 'display_name' doesn't have a default value
Copy after login

This issue arose due to a change in MySQL's default behavior. In MySQL version 5.6.13, STRICT mode is often enabled, which enforces stricter rules for data validation. As a result, fields without default values can no longer be left blank during insertion.

Resolution

To resolve this issue, it is necessary to change the MySQL STRICT mode setting. There are two possible solutions:

  1. Temporary Change: Run the following command in your MySQL console:

    SET GLOBAL sql_mode='';
    Copy after login

    This will temporarily disable STRICT mode for all subsequent queries.

  2. Permanent Change: Edit your MySQL configuration file (my.cnf). Locate the sql_mode setting and verify that STRICT_ALL_TABLES or any other strict mode option is not present. If found, comment out or remove those options.

After making either of these changes, restart the MySQL server, and the INSERT commands should execute successfully without the "Field Doesn't Have Default Value" error.

The above is the detailed content of Why am I getting the \'Field Doesn\'t Have Default Value\' error in MySQL STRICT Mode?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template