I have just started using Laravel (8) and a bit confused on how to properly fix this error.
I have seen multiple suggested solutions here but do not believe the accepted solution to be the better solution.
I was attempting to perform php artisan migrate:fresh
on a default Laravel project. I was able to solve this by using the solution that involves specifying a length to certain fields
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name', 50);
$table->string('email', 100)->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password', 24);
$table->rememberToken();
$table->timestamps();
});
The accepted solution is to modify Schema::defaultStringLength();
.
Is this just a personal preference?
Edit: I noticed an additional detail in the documentation.
If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength method within your AppServiceProvider:
I just so happened to be using version 5.7.28