當我在我的專案中執行命令列 doctrine:schema:update --force
時,我嘗試忽略兩個實體,如下所示:
/*** @ORM\Entity(只讀=true) * @ORM\Table(名稱=“view_tableau_de_bord”)*/ class ViewTableauDeBord { //... }
在我的doctrine.yaml檔案中:
doctrine: dbal: default_connection: default connections: default: url: '%env(resolve:DATABASE_URL)%' driver: 'pdo_pgsql' server_version: '12' charset: utf8 schema_filter: ~^(?!view_)~ # ...
Doctrine 不斷產生所有實體,而我的視圖位於 schema_filter
中。你對此有何解釋?這是我第一次在專案中使用此選項。
專案設定:
An entity marked with the flag
ThereadOnly=true
is not tracked for updates anymore but it is still possible to insert or delete rows, as explained in thedocumentation.##.doctrine:schema:update
在問題的答案中command will still take the table into account to update the schema.
「忽略 Doctrine2 實體執行架構管理器更新時」有 3 個有效選項可以忽略架構更新中的實體。
schema_filter
schema_filter
is not made to "filter" entity but to filter db table from doctrine awareness.這是一個範例:
這是一個典型的範例,您不希望每次更新架構時都會產生這樣的查詢。 So using# 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 is table is not used by your code in your project for is yoursis project your project for.schema_filter
Try to create a random table using raw sql and useyou can tell doctrine to ignore this table in his validation and update process.
doctrine:schema:validate
It work for. It will show
database is not in syncerror. 一旦將其放入 schema_filter 中,錯誤就不會再發生。
doctrine:migration:diff
schema_ignore_class 但是,如果您想避免在資料庫內產生實體,則可以從 Ernesto 的答案中的連結中找到: 僅從 Doctrine 2.7 版本開始工作。 您可以在這裡找到完整的範例:and
doctrine:schema:update執行架構管理器更新時忽略 Doctrine2 實體
#使用學說遷移 I strongly advise you to usedoctrine:migration:diff
then
doctrine:migration:migrateinstead of
doctrine:schema:updateto performbase . It's ok for local dev, but when in production it is a very bad practice.
https://symfony.com/bundles/DoctrineMigrationsBundle/current/index.html#