运行迁移时出现以下错误:
PDOException::(“” SQLSTATE [42S21]:列已存在:1060 Duplicate 列名'role_id'“)
<?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');
});
}
}
我删除了大多数已迁移的表,因为它带来了重复问题。可能与我现有的问题有关吗?
答案 0 :(得分:1)
尝试在终端中运行以下命令:
composer dump-autoload // updates whatever you changed in your migration
php artisan migrate:fresh // migrates migration from the start
如果这些方法不起作用,请发布您的列结构,以便我们更多地了解您的问题。