Home > Database > Mysql Tutorial > How to Fix MySQL Error 1364: 'Field Doesn't Have a Default Value'?

How to Fix MySQL Error 1364: 'Field Doesn't Have a Default Value'?

Barbara Streisand
Release: 2024-12-28 18:49:11
Original
677 people have browsed it

How to Fix MySQL Error 1364:

MySQL Error 1364: Resolving "Field Doesn't Have a Default Values"

When attempting an insert into a MySQL table, you may encounter the error message "Field 'CREATED_BY' doesn't have a default value" (Error 1364). This issue arises when a table field is defined with a NOT NULL constraint but lacks a default value, and an attempted insert does not explicitly specify a value for that field.

To resolve this error, you have the following options:

  • Disable STRICT_TRANS_TABLES SQL Mode:

    • Navigate to the MySQL configuration file (%PROGRAMDATA%MySQLMySQL Server 5.6my.ini)
    • Locate the line containing "sql-mode=STRICT_TRANS_TABLES"
    • Remove that line or replace "sql-mode=STRICT_TRANS_TABLES" with an empty string
    • Restart MySQL
  • Check Alternative Configuration File Locations:

    • If modifying the aforementioned configuration file doesn't resolve the issue, examine these additional potential locations:

      • /etc/my.cnf
      • /etc/mysql/my.cnf
      • ~/.my.cnf
  • Explicitly Specify Field Values in Insert Statement:

    • If the aforementioned methods are not suitable, explicitly specify values for all non-nullable fields in your insert statement, e.g.:

      insert into try (name, CREATED_BY) values ('abc', 'admin');
      Copy after login

Note: It is not recommended to make the field nullable or remove the trigger to suppress this error. These solutions compromise data integrity and may cause issues with other applications.

The above is the detailed content of How to Fix MySQL Error 1364: 'Field Doesn't Have a Default Value'?. 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