Based on my research, I would say that it can be either "you" or "MySQL". Check table definitions with SHOW CREATE TABLE table_name; . Pay attention to any fields defined using NOT NULL .
MySQL 5.6 Reference Manual: 13.2.5 INSERT Syntax :
Insert NULL into a column that was declared NOT NULL. For multi-line INSERT or INSERT INTO ... SELECT statements, the column is set to the implicit default value for the column data type. This number is 0 for numeric types, an empty string ('') for string types, and a null value for date and time types. INSERT IN ... SELECT statements are treated the same as inserting multiple rows because the server does not check the result set from SELECT until you see if it returns a single row. ( For a single-line INSERT, no warning appears when NULL is inserted into the NOT NULL column. Instead, the error fails with an error. )
This means that it doesn't matter which SQL mode you use. If you execute a single INSERT row (as per your code example) and insert a NULL value into a column defined using NOT NULL , it should not work.
At the same time, ironically, if you just omitted the value from the list of values, the following is indicated in the MySQL manual, in which case SQL mode matters:
If you are not working in strict SQL mode, any column is not explicitly specified, the value is set to the default value ( Explicit or Implicit ). For example, if you specify a list of columns that does not name all the columns in the table, unnamed columns have default values. The purpose of the default value is described in section 11.6 “Data Type Default Values”. See also section 1.7.3.3, “Restrictions on Invalid Data”.
So you cannot win! ;-) Joke. I would like to accept that NOT NULL in a field of a MySQL table really means that I will not accept the value NULL for a field when executing a single INSERT line, regardless of the SQL mode. ''
All of the above reads as follows:
To enter data in a NOT NULL column that does not have an explicit DEFAULT value, if the INSERT or REPLACE statement does not contain a value for the column, or the UPDATE statement sets the column to NULL, MySQL processes the column according to the current SQL mode:
If strict SQL mode is enabled , an error occurs for the transaction table and the rollback statement. For nontransactional tables, an error occurs, but if this happens for the second or next line of a multiline statement, the previous lines would be inserted.
If strict mode is not enabled, MySQL sets the column to an implicit default value for the column data type.
So, with a heart. Set your default values in the business logic (objects) and let the data layer take direction from that. Databases by default seem like a good idea, but if they weren't there, would you skip them? If a tree falls into the forest ...