Mysql: how to enable strict-mode to reject non-valid ENUM values

To have mysql reject invalid enum-values such as empty fields, you can enable strict mode.

You can do this in multiple ways, including real-time by setting a global var, unfortunately running an app with full rights on mysql table is really risky, as such we will focus on activating strict mode at configuration file level.

  1. edit /etc/mysql/my.cnf
  2. add|edit the following entry (new line):
    sql-mode = STRICT_ALL_TABLES
  3. save your changes & restart mysql server (/etc/init.d/mysql restart)

That’s it!

If you try inserting an empty value in an ENUM field, it should now be rejected by mysql.


Post a Comment

Your email is never published nor shared. You're allow to say what you want...