php - 无法生成表 "user"

标签 php symfony symfony-2.1 fosuserbundle

当我安装 FOSUserBundle ( official documentation ) 时,我尝试使用以下命令生成我的表 fos_user:

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

但控制台返回以下信息

Nothing to update - your database is already in sync with the current entity metadata

我使用 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: The class 'Krpano\UserBundle\Entity\User' was not found in the chain configured namespaces FOS\UserBundle\Entity, Krpano\ServicesBundle\Entity

你能帮帮我吗?

最佳答案

Nothing to update - your database is already in sync with the current entity metadata

暗示您的实体未注册,因为 AppKernel.php 中缺少声明。

Doctrine 只搜索活跃的 bundle。

添加行后:

new Krpano\UserBundle\KrpanoUserBundle(),

像那样:

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

        ); ...

试试这个:

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

如果 Doctrine 返回:

Database schema updated successfully! "1" queries were executed

您的问题已解决。

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

关于php - 无法生成表 "user",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145283/

相关文章:

php - 使用 PHPExcel 按行和列将 Excel 中的单元格合并在一起

php - symfony2 调用 is_granted in voter : how to avoid an infinite loop?

php - 如何将 Symfony2 表单与数组(不是请求)绑定(bind)?

php - 来自静态域或子域的 Symfony2 Assets 资源

php - Symfony 2.1 功能测试中的身份验证

php - 为包含的 php 文件定义一个单独的 css 文件?

php - 您如何确保查询始终返回结果并按相关性对结果进行排序?

php - 静态变量设置为 null,然后使用 if 语句检查该变量是否为 null

php - 无法测试 Symfony2 控制台命令

php - 交响乐 2 |修改具有文件(图片)字段的对象时出现表单异常