I want to empty a table in my MySQL database. How can I do that with Doctrine?
Truncating a table with Doctrine is as "simple" as:
$connection = $entityManager->getConnection();
$platform = $connection->getDatabasePlatform();
$connection->executeUpdate($platform->getTruncateTableSQL('my_table', true /* whether to cascade */));
But you have to know that MySQL will not be able to truncate any table once it has a foreign key constraint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With