在运行迁移时,我得到了以下错误:
PDOException::("SQLSTATE42S21:列已存在: 1060重复列名'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');
});
}
}我已经删除了大多数迁移的表,因为它带来了重复问题。这会否与我现时的问题有关?
发布于 2018-10-29 08:42:35
尝试在终端中运行以下命令:
composer dump-autoload // updates whatever you changed in your migrationphp artisan migrate:fresh // migrates migration from the start如果这些不工作,张贴您的列结构,以便我们可以更多地了解您的问题。
https://stackoverflow.com/questions/53040805
复制相似问题