-->

不可能生成表“用户”(Impossible to generate the table “user”

2019-09-21 18:02发布

当我安装FOSUserBundle( 官方文档 ),我试图生成我的表fos_user使用这个命令:

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

但是,控制台返回以下消息

没有更新 - 您的数据库已在同步与当前实体元

我使用的Symfony 2.1和最后一个版本FOSUserBundle。

应用程序/ AppKernel.php包含

new FOS\UserBundle\FOSUserBundle(),

应用程序/配置/ 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 /实体/ 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:类 'Krpano \ UserBundle \实体\用户' 链中的配置命名空间FOS \ UserBundle \实体,Krpano \ ServicesBundle \实体未发现

你能帮助我吗?

Answer 1:

没有更新 - 您的数据库已在同步与当前实体元

意味着你的实体是不是因为在AppKernel.php失踪宣言registred。

学说只搜索上捆绑谁是活跃的。

后加入一行:

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

你的问题是解决。

我的回答是刚刚完成卡洛斯·格拉纳多斯答案。



Answer 2:

new Krpano\UserBundle\KrpanoUserBundle(),

为了您的应用程序/文件AppKernel.php



Answer 3:

我有这个错误,它是由具有误删除造成@ORM\Entity()从我的实体类线。 D'哦。



Answer 4:

我有同样的问题,就像你一样。 你错过了为主义实体创建阳明。 这个文件是必需的学说在数据库中生成玛。

# 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

然后调用主义架构构建

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


Answer 5:

使用composer.phar dump-autoload --optimize

也挑起这个错误,在运行时:

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

如果你运行:

./composer.phar update

再这一切再次工作。



文章来源: Impossible to generate the table “user”