升级到Laravel 5.4和MySQL 5.7时,迁移不再起作用,我收到此错误:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at' (SQL: create table `tracker_paths` (`id` bigint unsigned not null auto_increment primar
y key, `path` varchar(255) not null, `created_at` timestamp not null, `updated_at` timestamp not null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB ROW_FO
RMAT=DYNAMIC) (SQL: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at' (SQL: create table `tracker_paths` (`id` bigint unsigned not null a
uto_increment primary key, `path` varchar(255) not null, `created_at` timestamp not null, `updated_at` timestamp not null) default character set utf8mb4 collate utf8mb4_unicode_ci en
gine = InnoDB ROW_FORMAT=DYNAMIC))
我该怎么办?
答案 0 :(得分:2)
这是由于sql模式STRICT_TRANS_TABLES,所以你有三个选择:
1)修复您的迁移。
2)在mysql连接中将strict更改为false:
'mysql' => $database = [
...
'strict' => false,
...
],
将禁用所有这些sql模式:
set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
3)设置自定义模式,删除STRICT_TRANS_TABLES
'mysql' => $database = [
...
'modes' => "set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'",
...
],