Create table in Mysql using Laravel

Asked

Viewed 298 times

0

I need to create a table with Laravel using the migrate command, the table would currently only have id. Normally two tables would be created, one with the name of the database I put containing the attributes, and another table that would manage data, would record whenever the table was modified. Only every time I create, these errors appear in Prompt:

inserir a descrição da imagem aqui

And that leads to two problems. The first is that the 2 tables are created, but the name of one of them is wrong (should be the name I put in the database):

inserir a descrição da imagem aqui

And the second is that they’re all empty, and I don’t know where those user table fields came from (which is under the wrong name):

inserir a descrição da imagem aqui

As I’m still learning to use, I don’t know what happens

3 answers

1

A change to Laravel from version 5.4 will cause mysql 5.6 or earlier versions to show this error. To fix just go in the file AppServiceProvider.php and in the method boot() you add Schema::defaultStringLength(191); remembering to import the class Illuminate\Support\Facades\Schema. It’ll look something like this:

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

source: https://laravel-news.com/laravel-5-4-key-too-long-error

0

It may be that the Mysql "innodb" option is disabled. To check if it is active enter the right of mysql bin open my.ini file, look for the line "Skip-innodb" see if it is commented. Unscrew the line by taking # from the top, save the file and restart Mysql. After that delete the table, create again and run migrate.

Note: I say this taking into account that the code inside the users' Migration is correct, because you did not put it there, but even so follows an example of how can be the code inside a users' migrate:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->timestamps();
    });
}

0

People already solved the problem. I had misspelled the name of the database but the main thing is that when I created the migrate came three PHP files with the table, users and password, I decided to delete these two and it worked. Weird but okay.

  • These are standard migrates of the Laravel it uses if you want the authentication scaffolding. It ran again because the error was in creating the users table that has an email field that is Unique. My lower answer explains the error better.

Browser other questions tagged

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