Home > Database > Mysql Tutorial > Why Does MySQL Throw Error 1364: 'Field Doesn't Have a Default Value' and How Can I Fix It?

Why Does MySQL Throw Error 1364: 'Field Doesn't Have a Default Value' and How Can I Fix It?

Mary-Kate Olsen
Release: 2024-12-22 03:17:10
Original
472 people have browsed it

Why Does MySQL Throw Error 1364:

MySQL Error 1364: Field Doesn't Have a Default Value

When encountering an error message "Field 'CREATED_BY' doesn't have a default value," it's important to understand its root cause. This error typically arises when a table column lacks a default value. In this case, a trigger is defined to automatically populate the "CREATED_BY" field with the user's identity upon insertion.

To resolve this error, it's crucial to disable the STRICT_TRANS_TABLES SQL mode. This mode is defined in the MySQL configuration file (my.ini or my.cnf). To make the change, locate the file in your MySQL installation directory and edit the following line:

[mysql]
sql-mode = STRICT_TRANS_TABLES
Copy after login

Remove STRICT_TRANS_TABLES from the sql-mode directive, as shown below:

[mysql]
sql-mode =
Copy after login

Save the changes and restart the MySQL service. This should resolve the error without making the column nullable or removing the trigger.

The above is the detailed content of Why Does MySQL Throw Error 1364: 'Field Doesn't Have a Default Value' and How Can I Fix It?. 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