4

当我安装FOSUserBundle官方文档)时,我尝试fos_user使用以下命令生成我的表:

php app/console doctrine:schema:update --force

但是控制台返回以下消息

无需更新 - 您的数据库已与当前实体元数据同步

我使用 Symfony 2.1 和 FOSUserBundle 的最新版本。

app/AppKernel.php包含

new FOS\UserBundle\FOSUserBundle(),

app/config/config.yml包含

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: Krpano\UserBundle\Entity\User

src/Krpano/UserBundle/Entity/User.php包含

namespace Krpano\UserBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="pouet")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

当我尝试访问我的网站时,我遇到了这个错误:

MappingException:在链配置的命名空间 FOS\UserBundle\Entity、Krpano\ServicesBundle\Entity 中找不到类“Krpano\UserBundle\Entity\User”

你能帮助我吗?

4

5 回答 5

4

无需更新 - 您的数据库已与当前实体元数据同步

暗示您的实体由于 AppKernel.php 中缺少声明而未注册。

Doctrine 仅搜索活跃的捆绑包。

添加行后:

new Krpano\UserBundle\KrpanoUserBundle(),

像那样:

public function registerBundles()
    {
            $bundles = array(    
            ...
            new Krpano\UserBundle\KrpanoUserBundle(),
            new FOS\UserBundle\FOSUserBundle(),    
            ...

        ); ...

尝试这个:

php app/console doctrine:schema:update --force

如果教义返回:

Database schema updated successfully! "1" queries were executed

你的问题解决了。

我的回答只是对 Carlos Granados 回答的补充。

于 2012-09-11T13:12:10.303 回答
3

添加

new Krpano\UserBundle\KrpanoUserBundle(),

到你的 app/AppKernel.php 文件

于 2012-08-28T09:03:28.327 回答
1

我有这个错误,这是由于不小心@ORM\Entity()从我的实体类中删除了该行。哦。

于 2013-05-29T17:13:47.997 回答
1

我和你有同样的问题。您错过了为 Doctrine Entity 创建 yml。Doctrine 需要这个文件来在你的数据库中生成 shema。

# src/Acme/UserBundle/Resources/config/doctrine/User.orm.yml
Acme\UserBundle\Entity\User:
    type:  entity
    table: fos_user
    id:
        id:
            type: integer
            generator:
                strategy: AUTO

然后在控制台更新作曲家的自动加载

composer dump-autoload

然后调用 Doctrine 模式构建器

php app/console doctrine:schema:update --force
于 2013-07-17T15:54:33.583 回答
0

使用composer.phar dump-autoload --optimize

运行时也会引发此错误:

php app/console cache:clear --env=prod --no-debug

如果你运行:

./composer.phar update

再次一切正常。

于 2013-05-25T22:50:40.830 回答