簡體   English   中英

刪除級聯laravel不起作用

[英]delete cascade laravel not working

我使用laravel 5.4刪除時遇到問題

我有3個表格:Users,Posts,Vechicles

用戶有很多帖子

車輛登錄

已擁有許多車輛

...無論如何...在為車輛表創建模式時,我使用2個外鍵:

$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
$table->foreign('post_user_id')->references('user_id')->on('posts');

當我要刪除帖子時,與要刪除的帖子相關的所有車輛....但是不起作用(它給出了關於約束的錯誤)

有人可以告訴我我錯了嗎? 我正在使用2個foregin鍵嗎?

檢查這個

$table->engine = "InnoDB";

使用一個外鍵解決此問題:

 Schema::create('vehicles', function (Blueprint $table) {
        $table->increments('id');
        $table->string('mark');
        $table->string('model');
        $table->integer('weight');
        $table->string('vehicle_state');
        $table->integer('post_id')->unsigned();
        $table->integer('post_user_id')->unsigned();
        $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM