SQLSTATE [42S02]:找不到基表或视图:1146表'pdone.BaseUser'不存在

时间:2015-07-16 01:03:00

标签: php symfony sonata-user-bundle sonata symfony-2.7

我在SonataUserBundle内使用FOSUserBundle 1.3.x-dev。我已按照UserBundle installation的每一步安装和配置所有步骤。这就是我在实体中所拥有的:

#src/Application/Sonata/UserBundle/Entity/User.php

namespace Application\Sonata\UserBundle\Entity;

use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\ORM\Mapping as ORM;

class User extends BaseUser
{
    /**
     * @var int
     */
    protected $id;

    /**
     * Get id.
     *
     * @return int $id
     */
    public function getId()
    {
        return $this->id;
    }
}

#src/Application/Sonata/UserBundle/Entity/Group.php

namespace Application\Sonata\UserBundle\Entity;

use Sonata\UserBundle\Entity\BaseGroup as BaseGroup;
use Doctrine\ORM\Mapping as ORM;

class Group extends BaseGroup
{
    /**
     * @var int
     */
    protected $id;

    /**
     * Get id.
     *
     * @return int $id
     */
    public function getId()
    {
        return $this->id;
    }
}

配置如下:

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

    group:
        group_class:   Application\Sonata\UserBundle\Entity\Group
        group_manager: sonata.user.orm.group_manager

    service:
        user_manager: sonata.user.orm.user_manager

    from_email:
        address:        noreply@pdi.com
        sender_name:    Mail Service

doctrine:
    dbal:
        types:
            json: Sonata\Doctrine\Types\JsonType
        default_connection:   default
        connections:
            default:
                driver:   pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8

                logging: true
                profiling: true
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        entity_managers:
          default:
            #I have tried here using mappings and without it - same issue
            mappings:
                FOSUserBundle: ~
                ApplicationSonataUserBundle: ~
                SonataUserBundle: ~
            auto_mapping: true
            filters:
                softdeleteable:
                  class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                  enabled: false

这是AppKernel.php

的一部分
...
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
...

这就是我在composer.json档案中所拥有的:

"require": {
    ...
    "friendsofsymfony/user-bundle": "1.3.x-dev",
    "sonata-project/admin-bundle": "~2.3",
    "sonata-project/user-bundle": "^2.2",
    "sonata-project/doctrine-orm-admin-bundle": "~2.3",
    "sonata-project/easy-extends-bundle": "^2.1",
    ...
    "leaseweb/memcache-bundle": "*"
}

我在app/Resources/FOSUserBundle/views/Security/login.html.twig中打印错误如下:

{{ error|trans({}, 'FOSUserBundle') }}

每次我尝试登录时都会收到如下消息:

  

执行'SELECT t0.username AS username1,t0.username_canonical AS username_canonical2,t0.email AS email3,t0.email_canonical AS email_canonical4,t0.enabled AS enabled5,t0.salt AS salt6,t0.password AS时发生异常   password7,t0.last_login AS last_login8,t0.locked AS locked9,t0.expired AS expired10,t0.expires_at AS expires_at11,t0.confirmation_token AS confirmation_token12,t0.password_requested_at AS password_requested_at13,t0.roles AS roles14,   t0.credentials_expired AS credentials_expired15,t0.credentials_expire_at AS credentials_expire_at16,t0.created_at AS created_at17,t0.updated_at AS updated_at18,t0.date_of_birth AS date_of_birth19,t0.firstname AS firstname20,t0。   lastname AS lastname21,t0.website AS website22,t0.biography AS tradition23,t0.gender AS gender24,t0.locale AS locale25,t0.timezone AS timezone26,t0.phone AS phone27,t0.facebook_uid AS facebook_uid28,t0.facebook_name AS   facebook_name29,t0.facebook_data AS facebook_data30,t0.twitter_uid AS twitter_uid31,t0.twitter_name AS twitter_name32,t0.twitter_data AS twitter_data33,t0.gplus_uid AS gplus_uid34,t0.gplus_name AS gplus_name35,t0.gplus_data AS   gplus_data36,t0.token AS token37,t0.two_step_code AS two_step_code38 FROM BaseUser t0 WHERE t0.username_canonical =?使用params [“admin”]限制1':SQLSTATE [42S02]:找不到基表或视图:1146表'pdone.BaseUser'不存在

为什么?这是FOSUserBundle问题还是SonataUserBundle问题?可以给我一些建议吗?

修改

我通过运行以下命令执行了另一项测试:

# php app/console doctrine:schema:update --dump-sql
Nothing to update - your database is already in sync with the current entity metadata.

# php app/console doctrine:schema:drop --force
Dropping database schema...
Database schema dropped successfully!

# php app/console doctrine:schema:create
ATTENTION: This operation should not be executed in a production environment.

Creating database schema...
Database schema created successfully!

再次没有成功,同样的问题!在所有测试中,我首先清除缓存

编辑2

我已经运行了doctrine:mapping:info,我得到了这个输出,为什么?

Found 18 mapped entities:
[OK]   FOS\UserBundle\Entity\User
[OK]   FOS\UserBundle\Entity\Group
[OK]   Sonata\UserBundle\Entity\BaseGroup
[OK]   Sonata\UserBundle\Entity\BaseUser
[OK]   Application\Sonata\UserBundle\Entity\User
[OK]   Application\Sonata\UserBundle\Entity\Group
[OK]   PDI\PDOneBundle\Entity\Representative
[OK]   PDI\PDOneBundle\Entity\Media
[OK]   PDI\PDOneBundle\Entity\Brand
[OK]   PDI\PDOneBundle\Entity\TerritoryBrand
[OK]   PDI\PDOneBundle\Entity\Email
[OK]   PDI\PDOneBundle\Entity\Company
[OK]   PDI\PDOneBundle\Entity\Action
[OK]   PDI\PDOneBundle\Entity\Message
[OK]   PDI\PDOneBundle\Entity\Territory
[OK]   PDI\PDOneBundle\Entity\TargetBrand
[OK]   PDI\PDOneBundle\Entity\Event
[OK]   PDI\PDOneBundle\Entity\Target

1 个答案:

答案 0 :(得分:0)

如果命令php app/console doctrine:schema:update --dump-sql未显示您的实体未映射的内容。

我的第一个猜测是你需要在config.yml而不是Sonata配置文档中添加auto_mapping,这样你的实体就会自动映射。

doctrine:
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        entity_managers:
            default:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                auto_mapping: true

同时检查您的app/AppKernel.php是否有扩展FOSUserBundle的SonataUserBundle:

new Sonata\UserBundle\SonataUserBundle('FOSUserBundle')