I've been doing a few experiments with ENUMs and SQL_MODE.
Not a lot of people realise that in MySQL, an ENUM can actually
contain one other value as well as the specified ones - no, not
NULL, but ANOTHER value, specifically, the empty string ''.
This can lead to trouble. The empty string is entered by MySQL
when it tries to insert an invalid value into the column. It does
also give a warning, but nobody takes any notice of those
right?
Demo schema:
CREATE TABLE enumtest (
id int not null auto_increment,
name varchar(100) NOT NULL,
status ENUM('ok','broken','decommissioned','narnia'),
PRIMARY KEY(id),
KEY(name),
KEY(status)
);
Now let's try some inserts...
INSERT INTO enumtest (name,status) VALUES
('Mark','ok'),
('Fred','broken'),
('Bob','decommissioned'); …
[Read more]