Place a size in the field $table->string('email
that will solve the problem, it complains that the size of the field is too large in the index creation, example of correction that in my understanding the email field does not have to be very large with 100 I believe to be a natural size:
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email', 100)->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Note : If you have more fields with type string
and you must índice
take preventative measures by passing size.
I also noticed that there are many fields with maximum size, this is not good, you need to study your tables, fields and keys, because I prefer to have control of the situation than to let the framework make all the decisions .
In addition to this, which in my experience is the best solution, that is, adjust the field sizes with previous studies, if using Laravel 5.4
change two keys in file config/database.php
:
from:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
to:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
Another option, but that may not be very good because some hosting will not let you change the settings of your services, option innodb_large_prefix
to your database by checking this option in the database MySQL
or MariaDB
.
Finally, if you want to set a default size of migrations
to string
, open the app\Providers\AppServiceProvider.php
and put the command Schema::defaultStringLength(191);
with size 191
, example :
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Schema::defaultStringLength(191);
}
public function register()
{
}
}
This is 4 ways to solve your problem, but, I prefer the first, because it gives me and guarantees reliability in what I am planning for my information repository.