嘿,我目前正在進行 Laravel 6 數據庫遷移,但是當我執行 php artisan migrate:fresh 時,以下錯誤跳到我身上: SQLSTATE [HY000]:一般錯誤:1215 無法添加外鍵約束(SQL:alter table category_postadd constraint category_post_category_id_foreignforeign key ( category_id) 參考id( categories) 在更新級聯上刪除級聯)我檢查了以下內容:錯別字引用順序錯誤自 Laravel 5.8 起從增量更改為大增量錯誤類型這是我的遷移代碼,希望您能看到我犯的錯誤,因為我找不到它。 // Table for storing Blog Posts Schema::create('posts', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('title'); $table->string('slug'); $table->string('read_time'); $table->string('summary'); $table->string('body'); /*$table->timestamps('created_at'); $table->timestamps('updated_at');*/ $table->timestamps(); }); // Table for storing categories Schema::create('categories', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name')->unique(); $table->string('slug')->unique(); $table->string('description'); $table->timestamps(); }); // Table for association of Categories with Blog Posts Schema::create('category_post', function (Blueprint $table) { $table->bigInteger('category_id'); $table->bigInteger('post_id'); $table->foreign('category_id')->references('id')->on('categories') ->onUpdate('cascade')->onDelete('cascade'); $table->foreign('post_id')->references('id')->on('posts') ->onUpdate('cascade')->onDelete('cascade'); $table->primary(['post_id', 'category_id']); }); // Table for association of Users with Blog Posts Schema::create('user_post', function (Blueprint $table) { $table->bigInteger('user_id'); $table->bigInteger('post_id'); });畢竟,目標是將類別和用戶與帖子相關聯,以便我可以在帖子上添加標簽和用戶。提前感謝您的幫助和好意,我對 Laravel 還很陌生,但我對 PHP 有很好的了解,所以如果您能解釋我做錯了什么,那就太好了 :)
- 1 回答
- 0 關注
- 168 瀏覽
添加回答
舉報
0/150
提交
取消