前提
usersテーブルとdchatテーブル(postテーブルみたいな)の
中間テーブルをmigrateしようとするとエラーが出てしまいます
考えられる原因が知りたいです
バージョンはlaravel8です
中間テーブルのコード
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('dchat_user', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('user_id'); $table->unsignedBigInteger('dchat_id'); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('dchat_id')->references('id')->on('dchats')->onDelete('cascade'); $table->unique(['user_id' , 'dchat_id']); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('dchat_user'); } };
エラーコード
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'dchat_user' already exists (SQL: create table `dchat_user` (`id` bigint unsigned not null auto_increment primary key, `user_id` bigint unsigned not null, `dchat_id` bigint unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci') {省略} database/migrations/2022_05_03_183006_create_dchat_user_table.php:25 Illuminate\Support\Facades\Facade::__callStatic("create")
もしよろしければご教授いただけないでしょうか。
回答2件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。