ERROR 1067 (42000): Invalid default value for ‘created_at’

This error will happen due to the MySQL server SQL mode settings. We can fix this issue easily by changing the sql_mode.

The issue is happening because inside the sql_mode we have “NO_ZERO_IN_DATE,NO_ZERO_DATE”. We need to remove it by running SQL command.

Let’s the check current sql_modes by running the following command

mysql> show variables like 'sql_mode'
# output
'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION'

“NO_ZERO_IN_DATE,NO_ZERO_DATE” is added as the sql_mode in mysql new versions. We just need to remove it from sql_mode. Run the following command to remove it:

mysql> set global sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

Now the error should be fixed. Happy coding. 🙂

Reference: