Good day. I have a very interesting question. In general, why when adding a non-existent value ('') in the field with a NOT NULL token, the query occurs and inserts a new record. Although, while returning Warning, but why Warning, and not Fatal Error?

Listing:

CREATE TABLE IF NOT EXISTS `exotichoroscopes_data` ( `id` int(4) NOT NULL AUTO_INCREMENT, `type` int(2) NOT NULL, `zodiac` int(1) DEFAULT NULL, `date_begin` varchar(10) DEFAULT NULL, `date_end` varchar(10) DEFAULT NULL, `name` varchar(200) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; 

In the type field it is not allowed to add an empty value! Same as in name .

  • You do not have the correct MySQL: D And what's the difference, Warning or Fatal Error, at least some error displays, informs you that something went wrong. If there was no error at all, then another conversation. - Elime

1 answer 1

From the documentation:

SunMicrosystems

Inserting NULL into a column that has not declared. For multiple-row INSERT statements or INSERT INTO ... SELECT statements for the column data type. This is a null string for all types of data types.

In mysql, columns have an implicit default value. In normal mode, if you insert multiple records at a time and do not specify a value for the NOT NULL record, the default value will be inserted instead of the NULL. Implicit default value for the numeric fields 0.

You can change this behavior by setting the appropriate sql mode: here is the documentation .

You need to look at the STRICT_ALL_TABLES and STRICT_TRANS_TABLES . Well, or put SQL_MODE in TRADITIONAL .

  • Too bad ... But thanks for the explanation! - RCuPeR