php artisan migrate
→
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_emai l_unique`(`email`))
MySQLのencodingがutf8mb4の場合は4バイトのため、255 * 4 = 1,020 バイトとなり、767バイトを超えてしまうためエラーが発生
カラムのlimitを191に制限 191 * 4 = 764バイトとなり制限以内に抑える
この設定変更前は php artisan migrate:rollback 等々のコマンドでもエラーが発生
設定前に php artisan migrate でエラーデータベースを作っていた場合は手動でデータベースを削除した後に設定をし直す
- Add the following to the app/Providers/AppServiceProvider boot method:
Schema::defaultStringLength(191);
- Don't forget to include the following at the top of the file:
use Illuminate\Support\Facades\Schema;
参考: