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
Remove STRICT_TRANS_TABLES from the sql-mode directive, as shown below:
[mysql] sql-mode =
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!