JohnM2 JohnM2 - 1 year ago 215
MySQL Question

How to truncate a table using Doctrine?

I want to empty a table in my MySQL database. How can I do that with Doctrine?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download