原则:类不是一个有效的实体或映射的超类,错误


Doctrine: Class is not a valid entity or mapped super class, error

所以我得到了著名的:

[RuntimeException]
Namespace "MyAppSomeToolBundle" does not contain any mapped entities.
doctrine:generate:entities [--path="..."] [--no-backup] name

我试着在stackoverflow上搜索任何答案,但似乎没有任何工作。看起来我的代码格式正确。我还有:

orm:
    auto_mapping: true

我得到错误时执行:

php app/console doctrine:generate:entities MyApp'SomeToolBundle'Entity'Lang
下面是我的代码:
<?php
    namespace MyApp'SomeToolBundle'Entity;
    use Doctrine'ORM'Mapping as ORM;
    /**
     *  @ORM'Entity
     *  @ORM'Table(name="phonetics")
     */
    class Lang
    {
        /**
         * @ORM'Id
         * @ORM'Column(type="integer")
         * @ORM'GeneratedValue(strategy="AUTO")
         */
        protected $id;
        /**
         * @ORM'Column(type="text")
         */
        protected $language;
        /**
         * @ORM'Column(type="text")
         */
        protected $text;
        /**
         * @ORM'Column(type="text")
         */
        protected $option1;
        /**
         * @ORM'Column(type="text")
         */
        protected $option2;
        /**
         * @ORM'Column(type="text")
         */
        protected $rated;
    }
?>

所以我不知道如何正确调试这个。如有任何建议,我将不胜感激。

为什么使用php app/console doctrine:generate:entities ?该错误告诉您已经手动创建了实体。

您可能希望通过在应用程序文件夹中执行以下命令来生成数据库表。

php -f ./vendor/doctrine/doctrine-module/bin/doctrine-module.php orm:schema-tool:update --force

你可以在执行前查看sql:

php -f ./vendor/doctrine/doctrine-module/bin/doctrine-module.php orm:schema-tool:update --dump-sql