I
I
Ivan Melnikov2018-03-16 09:09:01
MySQL
Ivan Melnikov, 2018-03-16 09:09:01

In MySQL 5.7, how can I make it so that when a value for an ENUM field (NN) is omitted in insert, an error is generated?

In non-strict and strict mode, if there is no value for an ENUM field (NOT NULL) in insert, then the first numbered member from the list of this ENUM is written to this field.
First, it is very strange that in this context, strict and non-strict modes do not differ. This is fine?
And secondly, how to make it as simple as possible, so that when a value for an ENUM field (NOT NULL) is omitted in insert, an error is generated?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-03-16
@immelnikoff

Do you have a case for the DEFAULT field is not set?
PS
This is the regular behavior of MySQL:
So the check can be done only by hanging a trigger on BEFORE INSERT / BEFORE UPDATE with checking the value and generating an error through SIGNAL .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question