The mysql field does not set the default value, and the insert statement does not set the field value to report an error solution

In MySQL 5.1, we may forget to give a default value to a field when designing a data table, such as 0 for int type data, an empty string for varchar type data, 0.0 for float type, and 0000-00-00 for datetime 00:00:00, but this field may not have a value when php writes data to the table. At this time, the database will automatically fill in the null value according to the data type.

However, when this php code is run on mysql5.6, an error is often reported. The typical prompts are as follows:

ERROR 1364 (HY000): Field 'name' doesn't have a default value

It is an error, indicating that a field does not have a default value.

In fact, for writing code, this automatic filling of null values ​​according to the type is very useful, especially in the production environment (the development environment can of course be stricter!).

So how can we make mysql5.6 behave the same as mysql5.1?

Take a look at my.cnf loaded when mysql is running, there is a sentence:

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

We delete the comma after the comma, that is, delete the configuration STRICT_TRANS_TABLES. STRICT_TRANS_TABLES, as the name suggests, executes the SQL statement in strict mode.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326783202&siteId=291194637