我正在运行laravel 5.4
并注意到事务回滚不起作用。我在settings.php
文件中将我的数据库引擎设置为InnoDB
,并尝试DB::rollback();
和DB::rollBack();
(即大写和小写b),但它不回滚我的数据库。Laravel事务回滚似乎不起作用
我写了一个单元测试波纹管。它创建一个记录,提交它,然后回滚。然而,最后的断言失败了。在回滚之后,数据库中仍然存在该记录。有什么我失踪?或者是否有laravel的错误?
public function testRollback()
{
$this->artisan('migrate:refresh', [
'--seed' => '1'
]);
DB::beginTransaction();
Season::create(['start_date' => Carbon::now(), 'end_date' => Carbon::now(),]);
DB::commit();
$this->assertDatabaseHas('seasons', [
'start_date' => Carbon::now(), 'end_date' => Carbon::now(),
]);
DB::rollBack();
// This assertion fails. It still finds the record after calling roll back
$this->assertDatabaseMissing('seasons', [
'start_date' => Carbon::now(), 'end_date' => Carbon::now(),
]);
}