我有一个非常简单的数据库,想要将其导入并创建实体。Doctrine (Symfony) 能够从数据库生成 YML 映射文件。但是当我随后尝试生成实体时,会出现以下错误:
[Doctrine\Common\Persistence\Mapping\MappingException]
Invalid mapping file 'SandboxBundle.Entity.Product.orm.yml' for class
'SandboxBundle\Entity\Product'.
我认为yml文件看起来很好,因为它是由Doctrine生成的,这是我们所希望的。为了确保,我使用在线yml验证器检查了它,结果显示它是OK的。我尝试生成实体的命令是:
app/console generate:doctrine:entities sandbox
以下是.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: { }
为了完整起见,这是类别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上有很多这种问题的实例。获取有关如何诊断这些类型错误的信息将非常有帮助,从而能够自己找到解决方法。