Symfony 2: How to avoid the sessions table being dropped by doctrine migrations?

Viewed 3148

I'm new to migrations, and I'm trying to stick to the automatically generated ones:

$ php app/console doctrine:migrations:diff
$ php app/console doctrine:migrations:migrate

The problem is that this drops my sessions table. What can I do to avoid that?

3 Answers

Another option is simply to tell Doctrine to ignore the table. You can use the schema_filter option as described in this SO post.

So, if your table is called sessions, add the following to config.yml (Symfony < 4) or doctrine.yaml (Symfony >=4 ):

doctrine:
    dbal:
      # standard database config here
      schema_filter: ~^(?!sessions)~

We had a large number of tables to ignore, so we took the opposite approach - we told Doctrine to only consider tables which began with a certain prefix, and set up listeners to ensure all our Doctrine-managed tables had a prefix. The use of listeners for table prefixes is documented at http://docs.doctrine-project.org/en/latest/cookbook/sql-table-prefixes.html and there's a SO post about the Symfony side of it here.

Related