Problem Summary
For MariaDB an insert statement can produce an error if you do not specify a column which has a NOT NULL constraint. However if the column is of data type ENUM instead the implicit default (first in the list) is used and the insert does not produce an error. I would like to get an error instead.
Details / What I tried
Error for number data type
On a table with with a number column with NOT NULL constraint I do get an error as expected
create table test_number (
name VARCHAR(40),
num tinyint(1) not null
);
insert into test_number (name, num) values ('small',null); # sanity check
insert into test_number (name) values ('small');
#Response: Error Code: 1364. Field 'num' doesn't have a default value
No Error for enum data type
On a table with with an ENUM column with NOT NULL constraint I do not get an error
create table test_enum (
name VARCHAR(40),
size ENUM('x-small', 'small', 'medium', 'large', 'x-large') not null
);
insert into test_enum (name, size) values ('small',null); # sanity check
#Response: Error Code: 1048. Column 'size' cannot be null
insert into test_enum (name, size) values ('small',default(size)); # sanity check 2
#Response: Error Code: 1364. Field 'size' doesn't have a default value
However the following insert statement is processed successfully
insert into test_enum (name) values ('small');
select * from test_enum;
|#|name |size |
|1|small|x-small|
As you can see the implicit default 'x-small' which is the first in the list of the create statement is used.
Database Configuration
I tried it on multiple versions of MariaDB >= 5.5, the output above was produced with 10.5.5.
SHOW VARIABLES LIKE '%version%';
|version|10.5.5-MariaDB-1:10.5.5+maria~focal|
I do use strict SQL_MODE for the database
SELECT REPLACE(@@SQL_MODE, ',', '\n');
#|STRICT_ALL_TABLES|
Desired Result
The above success insert actually happens implicitly in our application whenever we add an enum column and forget to adapt the corresponding code in the DAO Layer. I would like to get an error instead so that existing tests in the CI will fail.