从表约束了外键,但是迁移的时候没有执行外键这行名令,表添加成功了,也没报错,就是外键没有设置成功。
主表:
Schema::create('warestocks', function (Blueprint $table) {
$table->increments('id');
$table->string('username')->comment('用户名');
$table->integer('uid')->comment('用户id');
$table->timestamps();
});
从表:
Schema::create('warestock_goods', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->comment('产品名称');
$table->integer('good_id')->comment('产品名称');
$table->integer('num')->default(0)->comment('产品数量');
$table->integer('warestock_id')->unsigned()->comment('申请id');
$table->foreign('warestock_id')
->references('id')
->on('warestocks')
->onDelete('cascade');
$table->timestamps();
});