I'm trying to truncate a table, but everytime I try to run it through a test I get a PDOException:
There is no active transaction
I'm using the RefreshDatabase trait.
My code looks like this:
Model::query()->truncate();
I'm trying to truncate a table, but everytime I try to run it through a test I get a PDOException:
There is no active transaction
I'm using the RefreshDatabase trait.
My code looks like this:
Model::query()->truncate();
the error is caused by the truncate action
based on the answer on https://stackoverflow.com/a/1522974/6644975
when you execute a truncate statement the transaction is committed and then the TRUNCATE is executed and cannot be undone.
This affects the RefreshDatabase trait which uses a transaction for each and every test.
here's how it runs
RefreshDatabase creates a transactionstruncateTruncate commits the transactionRefreshDatabase tries to commit a transaction but will not be able to because it's already committed causing an error There is no active transaction