I have my mapped entity named Product, with just two columns: id
and name
.
If I add another column manually, i.e. stock_qty
directly with an SQL statement, the schema update tool will remote it, of course.
How can I prevent Doctrine remove my custom columns, not mapped to my entity?
Related issues: https://github.com/doctrine/doctrine2/issues/6434
You can define either a onSchemaColumnDefinition or a onSchemaAlterTableRemoveColumn event and ignore these columns.
Using the onSchemaColumnDefinition Event
In your bundle, create eg. src/AppBundle/EventListener/MyEventListener.php:
Then, register your event listener in your services:
Similar, you could do this:
Using the onSchemaAlterTableRemoveColumn Event
In your bundle, create eg. src/AppBundle/EventListener/MyEventListener.php:
Then, register your event listener in your services.yml:
When running:
should ignore the specified column(s). ("tableName"."columnName" in this case will not be deleted)
References:
Doctrine schema events
Doctrine Event Listeners