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:
Check Alternative Configuration File Locations:
If modifying the aforementioned configuration file doesn't resolve the issue, examine these additional potential locations:
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');
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!