Symfony2自动生成实体错误。

问题描述:

我有两个表新闻和news_category。为此,我使用symfony命令'doctrine:mapping:convert'创建了两个映射类。这两个文件如下。Symfony2自动生成实体错误。

  1. news.orm.yml。

    News: 
        type: entity 
        table: news 
        fields: 
         newsId: 
          id: true 
          type: integer 
          unsigned: false 
          nullable: false 
          column: news_id 
          generator: 
           strategy: IDENTITY 
        newsTitle: 
         type: string 
         length: 255 
         fixed: false 
         nullable: false 
         column: news_title 
        newsDescription: 
         type: text 
         nullable: false 
         column: news_description 
        newsStatus: 
         type: string 
         length: 255 
         fixed: false 
         nullable: false 
         column: news_status 
        createdAt: 
         type: date 
         nullable: false 
         column: created_at 
        manyToOne: 
        category: 
         targetEntity: NewsCategory 
         cascade: { } 
         mappedBy: null 
         inversedBy: null 
         joinColumns: 
          category_id: 
           referencedColumnName: category_id 
         orphanRemoval: false 
    lifecycleCallbacks: { } 
    

2)。 NewCategory.orm.yml

NewsCategory: 
type: entity 
table: news_category 
fields: 
    categoryId: 
     id: true 
     type: integer 
     unsigned: false 
     nullable: false 
     column: category_id 
     generator: 
      strategy: IDENTITY 
    categoryTitle: 
     type: string 
     length: 255 
     fixed: false 
     nullable: false 
     column: category_title 
    categoryDescription: 
     type: text 
     nullable: false 
     column: category_description 
lifecycleCallbacks: { } 

后,我已经使用了另一个symfony的命令“的信条:映射:导入”使用这个我再次生成两个文件中的实体目录News.php和NewsCategory.php

这是如下。

1)news.php

<?php 

    namespace Admin\NewsBundle\Entity; 

    use Doctrine\ORM\Mapping as ORM; 

/** 
    * News 
    * 
    * @ORM\Table(name="news") 
    * @ORM\Entity 
    */ 
    class News 
{ 
/** 
* @var integer 
* 
* @ORM\Column(name="news_id", type="integer", nullable=false) 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="IDENTITY") 
*/ 
private $newsId; 

/** 
* @var string 
* 
* @ORM\Column(name="news_title", type="string", length=255, nullable=false) 
*/ 
private $newsTitle; 

/** 
* @var string 
* 
* @ORM\Column(name="news_description", type="text", nullable=false) 
*/ 
private $newsDescription; 

/** 
* @var string 
* 
* @ORM\Column(name="news_status", type="string", length=255, nullable=false) 
*/ 
private $newsStatus; 

/** 
* @var \DateTime 
* 
* @ORM\Column(name="created_at", type="date", nullable=false) 
*/ 
private $createdAt; 

/** 
* @var \NewsCategory 
* 
* @ORM\ManyToOne(targetEntity="NewsCategory") 
* @ORM\JoinColumns({ 
* @ORM\JoinColumn(name="category_id", referencedColumnName="category_id") 
* }) 
*/ 
private $category; 

} 

和2)NewCategory.php

namespace Admin\NewsBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* NewsCategory 
* 
* @ORM\Table(name="news_category") 
* @ORM\Entity 
*/ 
class NewsCategory 
{ 
/** 
* @var integer 
* 
* @ORM\Column(name="category_id", type="integer", nullable=false) 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="IDENTITY") 
*/ 
private $categoryId; 

/** 
* @var string 
* 
* @ORM\Column(name="category_title", type="string", length=255, nullable=false) 
*/ 
private $categoryTitle; 

/** 
* @var string 
* 
* @ORM\Column(name="category_description", type="text", nullable=false) 
*/ 
private $categoryDescription; 

} 

问题是现在当我创建使用的实体 “学说:生成:实体” 它给了我以下错误。

D:\wamp\www\Symfony>php app/console doctrine:generate:entities AdminNewsBundle 
Generating entities for bundle "AdminNewsBundle" 

    [Doctrine\Common\Persistence\Mapping\MappingException] 
    Invalid mapping file 'Admin.NewsBundle.Entity.News.orm.yml' for class 'Admi 
    n\NewsBundle\Entity\News'. 

doctrine:generate:entities [--path="..."] [--no-backup] name 

遗憾的英文不好,请帮我从这个问题来,因为我是新来的Symfony2

+0

如果您使用'yml'映射,则不需要生成'Annotations'。尝试删除您的实体并再次运行该命令。另外,请确保您的YML文件正确缩进。你提供的是不正确的。 *(请参阅'news.orm.yml'中的manyToOne)* – Touki 2013-03-22 09:26:03

+0

是的,我的yml文件正确缩进becoz它生成dinhem我删除了我的实体,但仍然没有创建实体。感谢您的重播。 – 2013-03-22 09:55:53

尝试:

1) php app/console doctrine:mapping:convert yml ./src/Admin/NewsBundle/Resources/config/doctrine/metadata/orm --from-database --force --namespace="Admin\\NewsBundle\\Entity\\" 

为Linux 命名空间=“管理员\\ \\ NewsBundle Entity \\“,对于Win可能是namespace =”Admin \ NewsBundle \ Entity \\“

Watch tha t映射是正确的,有正确的名称和正确的语法。

2) php app/console doctrine:mapping:import AdminNewsBundle annotation 

3) php app/console doctrine:generate:entities AdminNewsBundle 
+0

它仍然给出相同的错误 – 2013-03-22 10:45:24

+0

我不知道这是如何“。”以文件名Admin.NewsBundle.Entity.News.orm.yml – 2013-03-22 10:46:18

+0

尝试删除此'。',然后生成。 – sean662 2013-03-22 11:34:26

尝试与该实体名称与naspace

Admin\NewsBundle\Entity\News: 

更换阳明的第一线为例。