Hi there , iam working on laravel project for an app , while i've done working with the migrations of the DB , but when i run pgp artisan migrate this error shows up and i didn't know what is the solutiin or what cause of this error,
the error : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'teams' already exists (Connection: mysql, SQL: create table teams (id bigint unsigned not null auto_increment primary key, name varchar(255) not null, sport_type_id bigint unsigned not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
the DB that have the error :
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('teams', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->unsignedBigInteger('sport_type_id');
$table->foreign('sport_type_id')->constraint()->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
}
public function down(): void {
Schema::dropIfExists('teams'); }
}; ```
the db that have the foreignkey that i have called in the table above :
``` <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sport_types', function (Blueprint $table) {
$table->id();
$table->string('sport_type');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sport_types');
}
}; ```