Laravel "php artisan migrate" 不工作 => SQLSTATE[22001]

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

我想创建一个login/registerwindow。现在我想创建我的数据库 tables。然后出现以下消息:

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))

用户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');
    }
};

我发现我可以将“字符串”更改为“文本”然后它就可以工作了(https://laracasts.com/discuss/channels/laravel/string-data-right-truncated-1406-error)。但我的问题是我无法在 table“迁移”中更改任何内容,因为据我所知它是由 laravel.

自动创建的

您可以尝试将 app/providers.php 编辑为以下代码。

use Illuminate\Support\Facades\Schema;

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

这将使迁移使用的所有 string 使用 191 作为默认长度。