[SOLVED] Laravel "php artisan migrate" is not working => SQLSTATE[22001]

Issue

I want to create a login/register window. now I wanted to create my database tables. Then comes the following message:

Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table

   Illuminate\Database\QueryException 

  SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'migration' at row 1 (SQL: insert into `migrations` (`migration`, `batch`) values (2014_10_12_000000_create_users_table, 1))

User Table:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->string('vertification_code')->nullable();
            $table->integer('is_verified')->default(0);
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
};

I found out that I can change the "string" to a "text" and then it can work(https://laracasts.com/discuss/channels/laravel/string-data-right-truncated-1406-error). But my problem is that I can’t change anything in the table "migration" because as far as I know it is created automatically by laravel.

Solution

You could try to edit your app/providers.php to below codes.

use Illuminate\Support\Facades\Schema;

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

It will make all of string that migration used use 191 as the default length.

Answered By – zaidysf

Answer Checked By – Clifford M. (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.