Disable MySQL Strict Mode and NO_ZERO_DATE Errors in Laravel Homestead

If you are using MySQL 8 or 5.7, on Laravel Forge, for example, use the command sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf. The options file /etc/mysql/conf.d/mysql.cnf is not the .cnf file we are using in this particular instance.

Then add the sql_mode options you need and wrap them in quotes under the [mysqld] group. The sql_mode options needed to disable NO_ZERO_IN_DATE errors are:

sql_mode = "ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

Then, restart MySQL with sudo service mysql restart and check your sql_mode if desired.

Note that NO_AUTO_CREATE_USER was removed in MySQL 8.0.11 so avoid using that option.

Solves MySQL Error Codes

  1. [ERR] 1067 – Invalid default value
  2. ERROR 1067 (42000): Invalid default value for

These errors are often seen in Laravel for created_at, updated_at, and deleted_at.

Leave a Reply

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.