首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel:运行迁移时的1060个重复列名

问Laravel:运行迁移时的1060个重复列名
EN

Stack Overflow用户
提问于 2018-10-29 07:37:38
回答 1查看 3.6K关注 0票数 2

在运行迁移时,我得到了以下错误:

PDOException::("SQLSTATE42S21:列已存在: 1060重复列名'role_id'")

代码语言:javascript
复制
<?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');
         });
    }
}

我已经删除了大多数迁移的表,因为它带来了重复问题。这会否与我现时的问题有关?

EN

回答 1

Stack Overflow用户

发布于 2018-10-29 08:42:35

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

  1. composer dump-autoload // updates whatever you changed in your migration
  2. php artisan migrate:fresh // migrates migration from the start

如果这些不工作,张贴您的列结构,以便我们可以更多地了解您的问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53040805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档