0

我正在使用内存中的 SQLite 来测试我的 Laravel 应用程序。然后我以这种方式定义一个表 Enterprise:

    Schema::create('Enterprise', function(Blueprint $table)
            {
                $table->increments('id');
                $table->string('name');
                $table->integer('address_id')->unsigned()->index()->nullable();
                $table->foreign('address_id')->references('id')
->on('Address')->onDelete('cascade');
                $table->timestamps();
            });

地址架构:

Schema::create('Address', function(Blueprint $table)
        {
            $table->increments('id');
            $table->timestamps();
        });

但是,当我运行测试时

$emp = Enterprise::find(1)->first();
$emp->delete();
$this->assertEquals(0, Enterprise::all()->count());
$this->assertEquals(0, Address::all()->count());

测试在第二个断言中失败,它没有在级联中删除:(

有谁知道解决办法??

4

0 回答 0