Reputation: 87719
When upgrading to Laravel 5.4 and MySQL 5.7, migrations are not working anymore and I'm getting this error:
[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))
What should I do?
Upvotes: 0
Views: 687
Reputation: 87719
This is due to sql mode STRICT_TRANS_TABLES, so you have three options:
1) Fix your migrations.
2) Change strict to false in your mysql connection:
'mysql' => $database = [
...
'strict' => false,
...
],
Which will disable all those sql 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'
3) Set custom modes, removing 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'",
...
],
Upvotes: 2