MySQL behaviour you should be aware of

I suggest changing the syntax for NOT NULL to “NOT” NULL.

If you’re not checking all values in your code logic (viz. PHP code or something like that) before attempting to perform the database manipulation you can fix it by (manually) add triggers to your tables to actually prevent a faulty insert/update:

mysql> CREATE TRIGGER check_constraint BEFORE INSERT ON table_name
    -> BEGIN
    ->   DECLARE error_msg varchar(255);
    ->   IF NEW.column_name = '' THEN
    ->     SET error_msg = 'Constraint my_constraint violated: ...';
    ->     SIGNAL SQLSTATE '45000' SET message_text = error_msg;
    ->   END IF;
    -> END;


Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.