Error Laravel migrate

Asked

Viewed 985 times

2

I’m having trouble turning the remote php artisan migrate in the terminal, a monstrous error appeared that I don’t understand because it occurred, I’ll send the link from github for you to take a look and give me a feedback, in the file I show how is the structure of my Migrations and below the error that appears in the terminal when I run the command. https://github.com/brenoo2018/migration.git

2 answers

2


  • 1

    The problem was right there, I made the change and it worked, thank you very much

0

Put a size in the field $table->string('email that will solve the problem, he complains that the size of the field is very large in the creation of the Indice, example of correction that in my understanding the email field does not need to be too 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();
});

Observing: if there are more fields with the type string and obliged to have a índice take preventive measures by passing the size.

I also noticed that there are many fields with maximum size, this is not good, need to have a study of their tables, fields and keys, because I prefer to have control of the situation than let the framework make all the decisions.


In addition to this, which in my experience is the best solution, that is, to adjust the sizes of the fields, with previous studies, if using the Laravel 5.4 change two keys in the file config/database.php:

of:

'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',

for:

'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',

Another option, but, that may not be very good because some hosting do not let change the settings of their services is to enable the option innodb_large_prefix to your database, checking this option in the database MySQL or MariaDB.


Finally if you want to put in your migrations a standard size for string, open the file app\Providers\AppServiceProvider.php and put the command Schema::defaultStringLength(191); with the size 191, example:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{   
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    public function register()
    {   
    }
}

These are 4 ways to solve your problem, but I prefer the first, because it gives me and ensures reliability in what I’m planning for my information repository.

References:

  • 1

    thanks for the remark Virgilio.

  • 1

    Complicated to take a negative vote, I believe that without reason always makes an invalid vote.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.