Level 1
Basically MySQL does not support Nested Transactions, so you need to adapt your testing.
This discussion gave me alternatives: https://github.com/laravel/framework/issues/18429
1 like
I am using transactions in my code and I am using the RefreshDatabase trait. This one creates a transaction of its own and then the rest of my transactions inside are performed by using MySQL savepoints.
I found the relevant code which is in Illuminate\Database\Concerns\ManageTransactions.
The problem is, that even when I tried to rollback to the savepoint right after it was created, it always throws that error.
ManageTransactions:127
/**
* Create a save point within the database.
*
* @return void
*/
protected function createSavepoint()
{
$this->getPdo()->exec(
$this->queryGrammar->compileSavepoint('trans'.($this->transactions + 1))
);
$this->getPdo()->exec(
$this->queryGrammar->compileSavepointRollBack('trans'.($this->transactions + 1))
);
}
I even tried if it was a mysql error but it works fine with the following code
START TRANSACTION;
SAVEPOINT trans2;
select count(*) as aggregate from `users` where `id` = 1 and `users`.`deleted_at` is null;
ROLLBACK TO SAVEPOINT trans2;
Please or to participate in this conversation.