Don*_*ggs 6 php mappingexception symfony doctrine-orm
我有一个非常简单的数据库,我试图导入,并从中创建实体.Doctrine(Symfony)能够从数据库生成YML映射文件.但是,当我临时尝试生成实体时,我收到以下错误:
[Doctrine\Common\Persistence\Mapping\MappingException]
Invalid mapping file 'SandboxBundle.Entity.Product.orm.yml' for class
'SandboxBundle\Entity\Product'.
Run Code Online (Sandbox Code Playgroud)
yml文件对我来说很好,因为我们期望它是由Doctrine生成的.只是为了确定,我检查了一个在线yml验证器,它说没关系.我用来尝试生成实体的命令是:
app/console generate:doctrine:entities sandbox
Run Code Online (Sandbox Code Playgroud)
.yml文件如下.请原谅这里粘贴文件导致的任何yml间距错误.正如我所说,yml文件是由doctrine生成的,并且确实通过了在线验证.
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: { }
Run Code Online (Sandbox Code Playgroud)
为了完整起见,这里是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: { }
Run Code Online (Sandbox Code Playgroud)
我在网上搜索了有关诊断映射例外的任何资源,但没有找到任何资源.我认为YML文件中存在导致实体生成器阻塞的内容.但错误消息没有说明可能是什么.我看到Stack Overflow上有很多关于这类问题的实例.获取有关如何诊断这些类型的错误的信息会非常棒,因此能够自己解决这个问题.
Mat*_*teo 10
已在文档中描述:
YAML文件中指定的类名应该是完全限定的.
因此,请尝试更改产品yaml定义,如下所示:
SandboxBundle\Entity\Product:
type: entity
table: product
indexes:
.....
Run Code Online (Sandbox Code Playgroud)
在其他映射文件中执行相同的操作.
希望这有帮助