我有两张table(顾客和预订)客户表格:
| id | | name | | created_at | | updated_at |
预订表:
| id | | product | | customer_id | | created_at | | updated_at |
如何创建迁移文件,在删除客户时删除与客户相关的所有预订?
5fjcxozz1#
只需将外键ondelete设置为级联
Schema::create('bookings_table', function (Blueprint $table) { $table->increments('id'); $table->string('product'); $table->unsignedInteger('customer_id'); $table->timestamps(); $table->foreign('customer_id') ->references('id') ->on('customer_table') ->onDelete('cascade') ->onUpdate('cascade'); });
1条答案
按热度按时间5fjcxozz1#
只需将外键ondelete设置为级联