Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hadees-ahmed's avatar

SAVEPOINT trans2 does not exist (Database transactions traite)

In certain tests, the application code initiates a database transaction (e.g., DB::beginTransaction()), but since the DatabaseTransactions trait has already started a transaction for the test, this results in a nested transaction scenario. MySQL, which I'm using as the database, does not natively support true nested transactions. Instead, it uses savepoints to simulate this behavior. However, this setup seems to be causing errors such as:

"SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT trans2 does not exist" Unexpected behavior due to the interaction between the outer and inner transactions. What I’ve Tried: Using RefreshDatabase Trait: I switched to the RefreshDatabase trait, but it didn’t resolve the issue for these specific tests.

My Question: What are the best practices or solutions to address this problem? Specifically:

Is there a way to configure MySQL or Laravel to better handle these nested transaction scenarios?

Are there any alternative approaches or configurations within Laravel that can help manage these transactions more effectively without sacrificing test performance?

Given that I need to run my tests in parallel to maintain reasonable test times, finding a solution that works efficiently in a parallel testing environment is crucial.

Any advice, insights, or shared experiences would be greatly appreciated!

2 likes
2 replies
hadees-ahmed's avatar

@mohab19 yeah I solved this problem using a patch and for me things are working okay but I need a proper solution to get rid off the patch that i applied

Please or to participate in this conversation.