Symfony Doctrine fixtures - do not purge all tables

3.5k views Asked by At

Is there any way to prevent purging one table when using Symfony Fixtures Bundle?

2

There are 2 answers

3
Matko Đipalo On

If you do the purging in a controller, you can write code like this:

use Doctrine\Common\DataFixtures\Purger\ORMPurger;
...

$excludedTables = ['my_table1', 'my_table42'];

$purger = new ORMPurger($this->getDoctrine()->getManager(), $excludedTables);

$purger->purge();

If you want do the purging in some class that does not have access to entity manager, you'll have to inject it in the constructor of the class, or as a parameter of the purging method. A rest of the code should look similar like before, only construction of the purger should look like this:

$purger = new ORMPurger($injectedEntityManager, $excluded);
0
Jasonoro On

It's a bit late however I created a PR that allows the use of a --exclude-table option. If/Once it has been merged you can use the following syntax:

php bin/console doctrine:fixtures:load --exclude-table=table_name --exclude-table=table_2_name

which will run the fixtures as normal but won't purge table_name or table_2_name.