Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine ORM: drop all tables without dropping database

Tags:

orm

doctrine

I have to work with an existing database (not managed with Doctrine) and I want to use doctrine only for new tables in this db.

is there a way to tell Doctrine to not drop the entire DB on reload but only the models defined in the yaml file ?

like image 207
gpilotino Avatar asked Sep 10 '09 13:09

gpilotino


2 Answers

I know this a very old question, and it appears you are using symfony.

Try:

app/console --env=prod doctrine:schema:drop --full-database

This will drop all the tables in the DB.

like image 91
Meezaan-ud-Din Avatar answered Sep 18 '22 23:09

Meezaan-ud-Din


For Symfony 3:

$entityManager = $container->get('doctrine.orm.entity_manager'); 

$entityManager->getConnection()->getConfiguration()->setSQLLogger(null);

$entityManager->getConnection()->prepare("SET FOREIGN_KEY_CHECKS = 0;")->execute();

foreach ($entityManager->getConnection()->getSchemaManager()->listTableNames() as $tableNames) {
        $sql = 'DROP TABLE ' . $tableNames;
        $entityManager->getConnection()->prepare($sql)->execute();
}
$entityManager->getConnection()->prepare("SET FOREIGN_KEY_CHECKS = 1;")->execute();
like image 38
Gebus Avatar answered Sep 19 '22 23:09

Gebus