【问题标题】:Error generating entity with Symfony2使用 Symfony2 生成实体时出错
【发布时间】:2014-09-02 12:05:48
【问题描述】:

我正在从 php 类生成一个实体:

<?php
// src/Printing/Productesbundle/Entity/User.php
namespace Printing\ProductesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="UsersStamp")
 */
class UserStamp
{
    /**
     * @ORM\Column(type="integer") 
     * @ORM\Id 
     * @ORM\GeneratedValue
     */
    private $id;

}

?>

当我执行时

php app/console doctrine:generate:entities Printing/ProductesBundle/Entity/UserStamp

它返回以下错误

 [Doctrine\ORM\Mapping\MappingException]
  Class "Printing\ProductesBundle\Entity\UserStamp" is not a valid entity or mapped super class.

我错过了什么??

谢谢!

PS:

这是我的教义配置:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

【问题讨论】:

  • $id 属性设置类似* @var integer* @ORM\Column(name="id", type="integer")* @ORM\GeneratedValue(strategy="AUTO") 的var 类型
  • 它仍然给我同样的错误:(
  • 基于文档symfony.com/doc/current/book/…,该命令的唯一目的是为实体生成适当的 getter 和 setter 以及可能的存储库类。我想如果你清除缓存php app/console cache:clear env=dev --no-debug 然后运行php app/console doctrine:generate:entities src/Printing/Productesbundle/Entity/UserStamp 它可能会工作
  • 我按照您的说明进行操作:-清理缓存.. 好的(env 之前缺少两个破折号)-运行学说:generate:entities 命令,但它仍然给我同样的错误。

标签: php symfony doctrine-orm


【解决方案1】:

你能试试下面的命令吗?

app/console doctrine:generate:entities PrintingProductesBundle:UserStamp

【讨论】:

  • 返回 ORMException:Unknown Entity namespace alias 'PrintingProductesbundle'.
  • 你是否在 AppKernel.php 中定义了你的包?
  • 是的。 $bundles = array(//... new Printing\ProductesBundle\ProductesBundle());
  • 'new Printing\ProductesBundle\ProductesBundle()' 是否正确?我认为它必须是'new Printing\ProductesBundle\PrintingProductesBundle()'
  • 我在这个包中生成了其他没有抛出任何错误的实体,所以我认为这不是问题所在。如果我使用正确的包名称 app/console doctrine:generate:entities ProductesBundle:UserStamp 执行命令,它将返回初始错误。
【解决方案2】:

我认为您需要执行类似的操作

php 应用程序/控制台原则:generate:entities ProductesBundle

【讨论】:

  • 该命令返回相同的错误,因为它生成 Productes Bundle 的每个实体。
【解决方案3】:

在尝试了一些技巧后,我找到了解决方案。

我猜这个错误是因为我之前从数据库中生成了实体。

要解决这个问题,您必须删除 config/doctrine 文件夹的内容。

感谢@Javad 继续努力!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    相关资源
    最近更新 更多