SQLSTATE[42S02]: 未找到基础 table 或视图:1146 Table 'pdone.BaseUser' 不存在
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pdone.BaseUser' doesn't exist
我正在使用 SonataUserBundle. I have follow every step on UserBundle installation 中的 FOSUserBundle 1.3.x-dev 进行安装和配置。这就是我在实体中所拥有的:
#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') }}
每次我尝试登录时,我都会收到这样的消息:
An exception occurred while executing '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 biography23, 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 = ? LIMIT 1' with params ["admin"]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pdone.BaseUser' doesn't exist
这是为什么?这是 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
错误非常明显,table BaseUser
不存在。
Base table or view not found: 1146 Table 'pdone.BaseUser' doesn't
exist
此外,请检查 FOSUserBundle User entity
class。
缺少一些注释(@ORM\Entity
和 @ORM\Table(name="...")
)。
例如
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
确保使用命令
生成数据库tables
app/console doctrine:schema:update --force
编辑:
如 Sonata reference 中所述,您是否尝试在 config.yml
中添加此代码?
# Enable Doctrine to map the provided entities
doctrine:
orm:
entity_managers:
default:
mappings:
FOSUserBundle: ~
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
如果命令 php app/console doctrine:schema:update --dump-sql
没有显示您的实体未映射。
我的第一个猜测是您需要在 config.yml 中添加 auto_mapping 而不是 Sonata 配置文档,这样您的实体将被自动映射。
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')
我正在使用 SonataUserBundle. I have follow every step on UserBundle installation 中的 FOSUserBundle 1.3.x-dev 进行安装和配置。这就是我在实体中所拥有的:
#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') }}
每次我尝试登录时,我都会收到这样的消息:
An exception occurred while executing '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 biography23, 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 = ? LIMIT 1' with params ["admin"]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pdone.BaseUser' doesn't exist
这是为什么?这是 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
错误非常明显,table BaseUser
不存在。
Base table or view not found: 1146 Table 'pdone.BaseUser' doesn't exist
此外,请检查 FOSUserBundle User entity
class。
缺少一些注释(@ORM\Entity
和 @ORM\Table(name="...")
)。
例如
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
确保使用命令
生成数据库tablesapp/console doctrine:schema:update --force
编辑:
如 Sonata reference 中所述,您是否尝试在 config.yml
中添加此代码?
# Enable Doctrine to map the provided entities
doctrine:
orm:
entity_managers:
default:
mappings:
FOSUserBundle: ~
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
如果命令 php app/console doctrine:schema:update --dump-sql
没有显示您的实体未映射。
我的第一个猜测是您需要在 config.yml 中添加 auto_mapping 而不是 Sonata 配置文档,这样您的实体将被自动映射。
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')