In the app service provider boot method you need to specify the key length as 191 as given in this article. https://laravel-news.com/laravel-5-4-key-too-long-error/ Also you need to use facade/ schema on top. See the code given.
table migration
Hello,
upon migration I am getting this error message:
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 password_resets add index password_resets_email_index(email))
What do I need to change?
migrations/create_password_resets_table.php
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up() { Schema::create('password_resets', function (Blueprint $table) { $table->string('email')->index(); $table->string('token'); $table->timestamp('created_at')->nullable(); }); }
Open your user and password_reset table in database/migrations folder
And just change the length of the email:
$table->string('email',191)->index();
And if you want to limit the length of every string in your project then follow this
Edit your app/Providers/AppServiceProvider.php file and inside the boot() method set a default string length:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
Please or to participate in this conversation.