Skip to content
Advertisement

SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘payments’ already exists (SQL: create table `payments`

When I migrate a table I see this error,

SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘payments’ already exists (SQL: create table payments

<?php

use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

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');
    }
}

Error

Advertisement

Answer

If you want to recreate the table, run php migrate:rollback first to delete the existing one. This command will run the down() method in the migration.

Then run php migrate to create the table again.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement