Your relationship is backwards in that case; auctions is the child as currently designed.
Jul 8, 2020
14
Level 2
Records not deleting with foreign key constraints
I want to delete product when the auction is deleted. I have used the foreign key constraints but the product is not deleting.
public function up()
{
Schema::create('auctions', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('product_id');
$table->timestamp('deadline');
$table->timestamps();
$table->foreign('product_id')
->references('id')
->on('products')
->onDelete('cascade');
});
}
Level 104
Cascading deletes will cascade, so if Product cascades to Auction, Auction will cascade to Bidding (based on your current schema and a foreign key constraint on biddings which is not shown)
If you move the product-auction relationship FK onto the products table , then providing both products and biddings will have an auction_id FK, both will delete whenever an auction record is deleted.
Please or to participate in this conversation.