问题
When I install FOSUserBundle (official documentation), I try to generate my table fos_user
using this command:
php app/console doctrine:schema:update --force
But console returns the following message
Nothing to update - your database is already in sync with the current entity metadata
I use Symfony 2.1 and the last version to FOSUserBundle.
app/AppKernel.php contains
new FOS\UserBundle\FOSUserBundle(),
app/config/config.yml contains
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 contains
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
}
}
And when I try to access to my website I have this error:
MappingException: The class 'Krpano\UserBundle\Entity\User' was not found in the chain configured namespaces FOS\UserBundle\Entity, Krpano\ServicesBundle\Entity
Can you help me?
回答1:
Nothing to update - your database is already in sync with the current entity metadata
Implies that your entity is not registred because of a missing declaration in AppKernel.php.
Doctrine only search on bundle who are active.
After added the line :
new Krpano\UserBundle\KrpanoUserBundle(),
Like that:
public function registerBundles()
{
$bundles = array(
...
new Krpano\UserBundle\KrpanoUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
...
); ...
Try this:
php app/console doctrine:schema:update --force
If Doctrine return:
Database schema updated successfully! "1" queries were executed
Your problem is resolve.
My answer is just a completion to Carlos Granados answer.
回答2:
Add
new Krpano\UserBundle\KrpanoUserBundle(),
To your app/AppKernel.php file
回答3:
I had this error and it was caused by having accidentally deleted the @ORM\Entity()
line from my entity class. D'oh.
回答4:
I had the same issue just like you. You missed to create yml for Doctrine Entity. This file is needed for Doctrine to generate shema in your database.
# 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
Then in console update autoload for composer
composer dump-autoload
Then call Doctrine schema builder
php app/console doctrine:schema:update --force
回答5:
Using composer.phar dump-autoload --optimize
Also provokes this error, when running:
php app/console cache:clear --env=prod --no-debug
If you run:
./composer.phar update
again it all works again.
来源:https://stackoverflow.com/questions/12145283/impossible-to-generate-the-table-user