Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel migration Specified key was too long; max key length is 767 bytes [duplicate]

I'm trying for migrate a laravel migration but i had an error :

Migrating: 2014_10_12_100000_create_password_resets_table

   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`))

my code is :

if (!Schema::hasTable('password_resets')) {
            Schema::create('password_resets', function (Blueprint $table) {
                $table->string('email')->index();
                $table->string('token');
                $table->timestamp('created_at')->nullable();
            });
        }
like image 503
Artin Zareie Avatar asked Sep 17 '18 14:09

Artin Zareie


1 Answers

You can set String Length manually by putting this

$table->string('name', 191); // You can put any number in exchange of 191

else

Put This in APP -> Providers -> AppServiceProvider

use Illuminate\Support\Facades\Schema;

public function boot() 
{
    Schema::defaultStringLength(191);
}
like image 118
Ashish Avatar answered Nov 12 '22 15:11

Ashish