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

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.


I know I am late to this question, but figured i would offer a suggestion.

import the session tables into your entities. even if you don't use it through the interfaces it creates, it will allow Doctrine to keep track of the tables, so that it knows they are ment to be there.

see: http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html