Monday, April 3, 2017

Laravel won't let me migrate a table because it already exists

I am trying to use Laravel Migration to create SQL tables but it won't let me.

Here is the error:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mytable' already exists

Here is my code:

        Schema::create('mytable', function (Blueprint $table) {
            $table->increments('id');
            $table->foreign('othertable_id')
                ->references('id')->on('othertable')
                ->onDelete('cascade');
            $table->string('variable');
            $table->timestamps();
    });

    }

    {
        Schema::drop('mytable');
    }

I have also checked if other migrations are called "mytable" but they are not, so I am not sure where this come from.

I tried the following:

First

php artisan migrate:refresh

Which gave me an error

And then I deleted the entire database altogheter and used:

php artisan migrate

And still got the error



via prgrm

Advertisement