{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/3602","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/3602/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/3602/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/3602/events","html_url":"https://github.com/laravel/framework/issues/3602","id":27857739,"number":3602,"title":"Invalid default value for 'created_at'","user":{"login":"mnpenner","id":1112998,"avatar_url":"https://avatars2.githubusercontent.com/u/1112998?v=3","gravatar_id":"","url":"https://api.github.com/users/mnpenner","html_url":"https://github.com/mnpenner","followers_url":"https://api.github.com/users/mnpenner/followers","following_url":"https://api.github.com/users/mnpenner/following{/other_user}","gists_url":"https://api.github.com/users/mnpenner/gists{/gist_id}","starred_url":"https://api.github.com/users/mnpenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnpenner/subscriptions","organizations_url":"https://api.github.com/users/mnpenner/orgs","repos_url":"https://api.github.com/users/mnpenner/repos","events_url":"https://api.github.com/users/mnpenner/events{/privacy}","received_events_url":"https://api.github.com/users/mnpenner/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":68,"created_at":"2014-02-19T08:18:45Z","updated_at":"2017-04-05T22:44:36Z","closed_at":"2014-02-19T22:44:54Z","body":"I was getting this error when using `$table->timestamps()` in a migration:\n\n> SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: create table `vehicles` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `code` varchar(255) not null, `description` text not null, `capacity` int not null, `company_id` int not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci)\n\nwith a MySQL backend. Turns out it's because I had `NO_ZERO_DATE` enabled. This actually makes sense though: `created_at` should either always contain a valid date, or it needs to be nullable. `0` does not make sense.\n\nI think a more sensible default is this:\n\n``` php\npublic function timestamps()\n{\n    $this->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));\n    $this->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));\n}\n```\n\nBut it only works on MySql 5.6+, I believe (you're only allowed one `CURRENT_TIMESTAMP` prior to that, for whatever reason). In which case maybe we should make `created_at` default to `CURRENT_TIMESTAMP` and `updated_at` be nullable? I'm just starting to learn Laravel, I'm not sure if `updated_at` is intended to start out blank and be updated after the first modify, or always contain a value.\n"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/292018682","html_url":"https://github.com/laravel/framework/issues/3602#issuecomment-292018682","issue_url":"https://api.github.com/repos/laravel/framework/issues/3602","id":292018682,"user":{"login":"robfrancken","id":14947976,"avatar_url":"https://avatars2.githubusercontent.com/u/14947976?v=3","gravatar_id":"","url":"https://api.github.com/users/robfrancken","html_url":"https://github.com/robfrancken","followers_url":"https://api.github.com/users/robfrancken/followers","following_url":"https://api.github.com/users/robfrancken/following{/other_user}","gists_url":"https://api.github.com/users/robfrancken/gists{/gist_id}","starred_url":"https://api.github.com/users/robfrancken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robfrancken/subscriptions","organizations_url":"https://api.github.com/users/robfrancken/orgs","repos_url":"https://api.github.com/users/robfrancken/repos","events_url":"https://api.github.com/users/robfrancken/events{/privacy}","received_events_url":"https://api.github.com/users/robfrancken/received_events","type":"User","site_admin":false},"created_at":"2017-04-05T22:44:36Z","updated_at":"2017-04-05T22:44:36Z","body":"Setting `strict => true` fixed it for me as well."}}
{"actor":{"display_login":"robfrancken"}}