valentin vannay


Invalid default value for 'created_at' with Laravel 5 / Homestead v0.3.3


Syntax error or access violation: 1067 Invalid default value for 'created_at'

Laravel 5.0.16 and Homestead 0.3.3.   I came accross this problem after updating my version of homestead (on this version of homestead the MySQL version has been updated). It took me some time to find the solution but with the help of Github users I finally fix it and wanted to share it one more time here. The full Github conversation can be found here. There are a few different solutions but the simpliest one is probalby the one given by the user Stayallive.   You simply have to modifiy the laravel database configuration file ( /config/database.php ) And set the MySQL strict mode to true:
// config/database.php -- Line 64
'mysql' => [
	'driver'    => 'mysql',
	'host'      => env('DB_HOST', 'localhost'),
	'database'  => env('DB_DATABASE', 'forge'),
	'username'  => env('DB_USERNAME', 'forge'),
	'password'  => env('DB_PASSWORD', ''),
	'charset'   => 'utf8',
	'collation' => 'utf8_unicode_ci',
	'prefix'    => '',
	'strict'    => true,
The php artisan migrate command should now work just fine.  

MySQL Strict Mode

To guard against ignored typos and syntax errors in SQL, or other unintended consequences of various combinations of operational modes and SQL statements, InnoDB provides a strict mode of operations. In this mode, InnoDB raises error conditions in certain cases, rather than issuing a warning and processing the specified statement (perhaps with unintended behavior). This is analogous to sql_mode in MySQL, which controls what SQL syntax MySQL accepts, and determines whether it silently ignores errors, or validates input syntax and data values. Since InnoDB strict mode is relatively new, some statements that execute without errors with earlier versions of MySQL might generate errors unless you disable strict mode.
  To read more about the MySQL strict mode follow this link to access the documentation.   I hope this will help someone ;)