Laravel Migrations - 创建时间戳时出现的问题

che*_*505 13 php mysql migration laravel

我正在尝试在我的Laravel实例上运行迁移.它们只是默认迁移(用户和密码重置),但是当它尝试生成时间戳时会抛出此错误:

 [Illuminate\Database\QueryException]
 SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: create table `
 users` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) n
 ot null, `password` varchar(60) not null, `remember_token` varchar(100) null, `created_at` timestamp default 0 not
 null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci)
Run Code Online (Sandbox Code Playgroud)

以及PDOException:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at'
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

谢谢.

Moh*_*ngh 20

我一直面临同样的错误.鉴于解决方案确实工作正常,我想帮助laravel开发人员.只需在config/database.php中添加以下行

'mysql' => array(
   'strict'    => true
),
Run Code Online (Sandbox Code Playgroud)


Tom*_*Tom 10

这是因为MySQL不接受零作为有效的默认日期,因此表创建未通过创建的约束检查.

您可能已NO_ZERO_DATE在MySQL配置中启用了.将此设置为off将允许您创建表,或者删除默认值0或将其更改为CURRENT_TIMESTAMP.

您可以在此处找到有关此确切问题的更多信息:https://github.com/laravel/framework/issues/3602