Ignore entity or table when running Doctrine2 schema update command

Recently I came accross a problem with entity that was mapped to view in database. In such scenario calling doctrine:schema:update command was producing errors.
I know that we can create custom schema based command tool but I think that my solution is easier and more efficient. The solution is using Doctrine2: postGenerateSchema event listener – to remove entity or table (depending on context) from Schema:

And register listener:

I have presented both versions: when we want to ignore tables and entities – you should select the most appropriate for you.

Note that Schema instance is created (generated) – not executed. In this case calling dropTable method means unset table from Schema instance. If you call:

you will receive generated schema SQL without tables you want to ignore.

Rate this post