【发布时间】:2018-08-30 05:37:02
【问题描述】:
我使用SET DEFAULT 将外键约束为:
public function up()
{
Schema::create('phong', function (Blueprint $table) {
$table->engine='InnoDB';
$table->bigIncrements('p_id');
$table->string('p_ma',50);
$table->string('p_ten',50);
$table->unsignedTinyInteger('p_soNguoi')->default('0');
$table->text('p_ghiChu',200)->nullable();
$table->unique(['p_ma','p_ten']);
$table->timestamp('p_taoMoi')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('p_capNhat')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->unsignedTinyInteger('p_trangThai')->default('2');
$table->unsignedTinyInteger('lp_ma');
$table->unsignedTinyInteger('k_ma');
$table->foreign('lp_ma')->references('lp_ma')->on('loaiphong')->onDelete('SET DEFAULT')->onUpdate('SET DEFAULT');
$table->foreign('k_ma')->references('k_ma')->on('khu')->onDelete('SET DEFAULT')->onUpdate('SET DEFAULT');
});
}
但这不起作用,这个错误是:外键约束在 正确形成。 当我想从表 'khu' 或 'loaiphong' 中删除一行时,该表的数据不会被删除。任何想法?谢谢
【问题讨论】:
-
我将“nullable()”用于“lp_ma”和“k_ma”作为您的链接。但它不起作用:(。我不知道为什么?