I'm using FOSUserBundle 1.3.x-dev from within SonataUserBundle. I have follow every step on UserBundle installation to install and configure all. This is what I have at entities:
#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;
}
}
This is how configuration looks like:
#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
This is a piece of 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(),
...
This is what I have at composer.json
file:
"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": "*"
}
I print the error in app/Resources/FOSUserBundle/views/Security/login.html.twig
as follow:
{{ error|trans({}, 'FOSUserBundle') }}
Every time I try to login I got a message like this:
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
Why is that? Is this a FOSUserBundle problem or a SonataUserBundle issue? Can any give me some advice around this?
EDIT
I have performed another test by running the commands below:
# 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!
And again no success, same issue! At all test I clear first the cache
EDIT 2
I've run doctrine:mapping:info
and I got this output, why?
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
The error is very explicit, the table BaseUser
doesn't exist.
Base table or view not found: 1146 Table 'pdone.BaseUser' doesn't exist
Moreover, please check the FOSUserBundle User entity
class.
Some annotations (@ORM\Entity
and @ORM\Table(name="...")
) are missing.
For example
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
Make sure to generate the database tables with the command
app/console doctrine:schema:update --force
EDIT:
As mentioned in the Sonata reference, did you tried to add this code in your config.yml
?
# Enable Doctrine to map the provided entities
doctrine:
orm:
entity_managers:
default:
mappings:
FOSUserBundle: ~
ApplicationSonataUserBundle: ~
SonataUserBundle: ~