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.