我有一個非常簡單的數據庫,我試圖導入並創建實體。 Doctrine(Symfony)能夠從數據庫生成YML映射文件。但是,當我subsiquently嘗試生成實體,我得到以下錯誤:Symfony2/Doctrine2試圖生成實體時無效映射文件異常
[Doctrine\Common\Persistence\Mapping\MappingException]
Invalid mapping file 'SandboxBundle.Entity.Product.orm.yml' for class
'SandboxBundle\Entity\Product'.
的YML文件看起來好像沒什麼問題,正如我們期望的是,它是由學說產生。只是可以肯定的,我檢查了一個在線的yml驗證程序,它說這是確定的。我用來嘗試生成實體的命令是:
app/console generate:doctrine:entities sandbox
接下來是.yml文件。請原諒在此粘貼文件導致的任何yml間距錯誤。正如我所說的,yml文件是由教條生成的,並且通過了在線驗證。
Product:
type: entity
table: product
indexes:
category_id:
columns:
- category_id
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
productname:
type: string
nullable: true
length: 10
fixed: false
comment: ''
categoryId:
type: integer
nullable: true
unsigned: false
comment: ''
column: category_id
lifecycleCallbacks: { }
爲了完整起見,這裏是Category yml文件。該錯誤在產品上,但我認爲這是因爲產品首先被處理。
Category:
type: entity
table: category
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
categoryname:
type: string
nullable: true
length: 50
fixed: false
comment: ''
lifecycleCallbacks: { }
我在網上搜索了與診斷映射例外有關的任何資源,但沒有找到任何資源。我認爲在YML文件中有一些東西會導致實體生成器窒息。但是,錯誤信息並沒有說明可能是什麼。我看到Stack Overflow上有很多這類問題的實例。能夠獲得關於如何診斷這些類型的錯誤的信息是非常好的,因此能夠爲我們自己弄清楚。
唐,它不是一個解決方案,但你可以選擇使用'verbose'選項運行'生成實體'命令,這將爲您提供一個PHP堆棧轉儲,然後您可以開始深入研究Doctrine代碼,至少可以查看失敗的原因,然而,如果你打算開始在供應商代碼中添加代碼,添加診斷「print_」語句等,你在Symfony的測試實例中執行這個測試,這是專門爲此目的而創建的。 。 – 2015-04-03 19:25:46