migration時に構文エラー
エラー内容は
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'json null, `s3_bucket` varchar(191) null) default character set utf8mb4 collate ' at line 1 (SQL: create table `exports` (`id` bigint unsigned not null auto_increment primary key, `created_at` timestamp null, `updated_at` timestamp null, `created_by` bigint unsigned null, `settings` json null, `s3_bucket` varchar(191) null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
at /Users/test/Desktop/test/src/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
migrationファイルに構文のエラーがあるとのことだが、どこにエラーがあるのかさっぱり分からなかった。
検索を進めると、以下の記事を発見。
https://stackoverflow.com/questions/58721612/error-sqlstate42000-syntax-error-or-access-violation-1064-you-have-an-error
こちらをもとに、読み進めると、次の一文がおかしいようだ。migrationファイルのカラムの中でjson型にしているものを修正する必要がある。
(MySQL server version for the right syntax to use near 'json null,)
修正
そこで、githubにissueとして上がっていたので、それを参考にすると、
私の該当のmigrationファイルはもともと以下のようになっていたが、これが問題らしい。
×××××_create_×××.php
$table->json('search')->nullable();
修正後
×××××_create_×××.php
$table->json('search')->charset(null)->nullable()->change();
参考:githubで参考にしたissue。
https://github.com/doctrine/dbal/issues/3714
追記
私の場合は原因は不明だが、json型が読み込めずにエラーがでていたのでjson型をtext型に変更した。
$table->json('chart_state')->charset(null)->nullable()->change();
を
$table->text('chart_state')->charset(null)->nullable();
また、storage/logに以下のようなエラーが排出された
[2020-04-23 07:56:55] local.ERROR: View [base] not found. (View: /Desktop/***/src/resources/views/home.blade.php) {"userId":1,"exception":"[object] (ErrorException(code: 0): View [base] not found. (View: /Desktop/***/src/resources/views/home.blade.php) at /Desktop/***/src/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:137, InvalidArgumentException(code: 0): View [base] not found. at /Desktop/****/src/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:137)
なので、.envの
.env
APP_DEBUG=true
から
APP_DEBUG=false
へ変更