I try to ignore two entities when I execute the command line doctrine:schema:update --force
in my project who is writing like this :
/**
* @ORM\Entity(readOnly=true)
* @ORM\Table(name="view_tableau_de_bord")
*/
class ViewTableauDeBord
{
//...
}
In my doctrine.yaml configuration file:
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_pgsql'
server_version: '12'
charset: utf8
schema_filter: ~^(?!view_)~
# ...
Doctrine keeps generating all entities while my views are in the schema_filter
. Do you have an explanation about this ? It's my first time with this option in a project.
Configuration du projet:
schema_filter
is not made to "filter" entity but to filter db table from doctrine awareness.
Here is an example :
Assuming you manually create a table that is updated from a custom raw php cronjob called view_booking_by_customer_per_year
, this table is not used by your code in your project but is used for data analysis.
This is a typical example where you do not want doctrine to generate a query like this each time you want to update your schema.
DROP TABLE view_booking_by_customer_per_year; // NO I DONT WANT THIS
So using schema_filter
you can tell doctrine to ignore this table in his validation and update process.
Try to create a random table using raw sql and use doctrine:schema:validate
.
It will show database is not in sync
error.
Once you put it in schema_filter, the error won't occur anymore.
It work for doctrine:migration:diff
and doctrine:schema:update
But if you want to avoid an entity to be generated inside the database there is this from the link in the answer of Ernesto:
schema_ignore_classes:
- Reference\To\My\Class
- Reference\To\My\OtherClass
Only working since Doctrine 2.7 version. You can find the complete example here : Ignore a Doctrine2 Entity when running schema-manager update
I strongly advise you to use doctrine:migration:diff
then doctrine:migration:migrate
instead of doctrine:schema:update
to perform change on database. It's ok for local dev, but when in production it is a very bad practice.
https://symfony.com/bundles/DoctrineMigrationsBundle/current/index.html