MySQL: How to Fix “Field Doesn’t Have A Default Value” Error

Share

MySQL or MariaDB install has default value of sql mode named STRICT_TRANS_TABLES.

The MySQL docs for STRICT_TRANS_TABLES state:

Strict mode controls how MySQL handles input values that are invalid or missing. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.)

To fix the issue, edit /etc/mysql/mariadb.conf.d/50-server.cnf in Ubuntu 22, add the following line inside [mysqld]group:

sql-mode="NO_ENGINE_SUBSTITUTION"

Save the file and restart MySQL service.

Leave A Reply

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