SQLSTATE[42S01]: 基表或视图已经存在:1050 表 'payments' 已经存在(SQL:创建表 `payments`

4 php mysql laravel

当我迁移表时,我看到此错误,

SQLSTATE[42S01]: 基表或视图已经存在:1050 表 'payments' 已经存在(SQL:创建表 payments

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePaymentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payments', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->string('resnumber');
            $table->string('course_id')->default('vip');
            $table->string('price');
            $table->boolean('payment')->default(false);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('payments');
    }
}
Run Code Online (Sandbox Code Playgroud)

错误

小智 6

如果您使用的是 Laravel 5.5,则可以执行php artisan migrate:fresh. 此命令将删除所有表,然后再次创建它们。我希望它有帮助。


Ale*_*nin 1

如果要重新创建表,php migrate:rollback请先运行删除现有表。此命令将运行down()迁移中的方法。

然后php migrate再次运行创建表。