I just don't understand for the life of me how this error's happening upon running php artisan migrate
after creating a new table.
I've searched the web and SO and tried every single suggestion out there (like php artisan migrate:fresh
) but nothing seems to be working.
What can I do to rectify this problem as this is holding me up big time?
SQLSTATE[42S01]: Base table or view already exists: 1050 Table
'posts' already exists (SQL: create table `posts` (`id` bigint
unsigned not null auto_increment primary key, `user_id` int
unsigned not null, `body` varchar(140) not null, `created_at`
timestamp null, `updated_at` timestamp null) default character set
utf8mb4 collate 'utf8mb4_unicode_ci')
Migration:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user_id')->unsigned();
$table->string('body', 140);
$table->timestamps();
$table->foreign('user_id')->references('id')->on('user')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
Please drop the tables before running the migrate command or try php artisan migrate:fresh command.