Laravel:1060运行迁移时列名重复

Laravel:1060运行迁移时列名重复,laravel,database-migration,Laravel,Database Migration,运行迁移时,我遇到以下错误: PDOException::(“SQLSTATE[42S21]:列已存在:1060重复 列名'role_id') 尝试在终端中运行以下命令: composer dump autoload//更新迁移过程中所做的任何更改 php-artisan-migrate:fresh//从一开始就迁移 如果这些都不起作用,请发布您的列结构,以便我们了解您的问题。您是否在运行迁移之前删除了此迁移?为什么不运行新迁移文件来编辑用户表?如果您的数据库中已有该表,或者您已经运行了迁移。如

运行迁移时,我遇到以下错误:

PDOException::(“SQLSTATE[42S21]:列已存在:1060重复 列名'role_id')


尝试在终端中运行以下命令:

  • composer dump autoload//更新迁移过程中所做的任何更改
  • php-artisan-migrate:fresh//从一开始就迁移

  • 如果这些都不起作用,请发布您的列结构,以便我们了解您的问题。

    您是否在运行迁移之前删除了此迁移?为什么不运行新迁移文件来编辑用户表?如果您的数据库中已有该表,或者您已经运行了迁移。如果您可以发布DB structurather,这意味着您已经添加了该列,但它不起作用,则更好。现在用户表是空的,我无法登录。更新:我再次注册为用户,现在可以登录了。现在的情况与创建所有迁移之前一样。但这些都是旧表,都存在于编辑器中。如果我必须重新创建所有迁移,那对我来说就是浪费时间。你能告诉我是否可以在编辑器中使用所有现有的迁移吗?不知怎么的,迁移现在可以正常工作了。幸运的是,我不必从头开始创建所有那些旧的迁移。如果您有一个种子机,那么使用以下命令
    php artisan migrate:fresh--seed
    <?php
    
    use Illuminate\Support\Facades\Schema;
    
    use Illuminate\Database\Schema\Blueprint;
    
    use Illuminate\Database\Migrations\Migration;
    
    class CreateUsersTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
    
            if(!Schema::hasTable('users')) {
                Schema::create('users', function (Blueprint $table) {
                    $table->increments('id');
                    $table->string('name');
                    $table->string('email')->unique();
                    $table->timestamp('email_verified_at')->nullable();
                    $table->string('password');
                    $table->rememberToken();
                    $table->timestamps();
                });
            }
    
            Schema::table('users', function (Blueprint $table) {
                $table->integer('role_id')->unsigned();
                $table->string('first_name')->nullable();
                $table->string('middle_name')->nullable();
                $table->string('last_name')->nullable();
                $table->string('city')->nullable();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('users');
    
            Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('role_id');
             });
        }
    }