[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_email_uniq(email))Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);
$table->string('role', 32);
$table->string('confirmation_code');
$table->boolean('confirmed')->default(true);
$table->timestamps();
$table->unique('email', 'users_email_uniq');
});unique(), which I have done. It still gives the error. What is going on here?1 Answers
CabRes::where('m__Id', 46)
->where('t_Id', 2)
->where(function($q) {
$q->where('Cab', 2)
->orWhere('Cab', 4);
})
->get();whereIn():CabRes::where('m__Id', 46)
->where('t_Id', 2)
->whereIn('Cab', $cabIds)
->get();
2 Answers
ActiveOldestVotes
282
Specify a smaller length for your e-mail:
$table->string('email', 250);
Which is the default, actually:$table->string('email');
And you should be good.For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post:As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:use Illuminate\Database\Schema\Builder;
public function boot()
{
Builder::defaultStringLength(191);
}