P粉1868974652023-08-27 17:01:05
An entity marked with the flag readOnly=true
is not tracked for updates anymore but it is still possible to insert or delete rows, as explained in the documentation.
The doctrine:schema:update
command will still take the table into account to update the schema.
在问题的答案中“忽略 Doctrine2 实体运行架构管理器更新时” 有 3 个有效选项可以忽略架构更新中的实体。
P粉4550931232023-08-27 14:04:02
schema_filter
is not made to "filter" entity but to filter db table from doctrine awareness.
这是一个示例:
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.
这是一个典型的示例,您不希望每次更新架构时都生成这样的查询。
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.
一旦将其放入 schema_filter 中,错误就不会再发生。
It work for doctrine:migration:diff
and doctrine:schema:update
但是,如果您想避免在数据库内生成实体,则可以从 Ernesto 的答案中的链接中找到:
schema_ignore_classes: - Reference\To\My\Class - Reference\To\My\OtherClass
仅从 Doctrine 2.7 版本开始工作。 您可以在这里找到完整的示例: 运行架构管理器更新时忽略 Doctrine2 实体
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