Unrecognized field: usernameCanonical for symfony2 FosUserbundle

I got this error when try to login to my system. I searched in internet and find this could be caused by several problems, of cause if your configuration is the following:
  orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: italy
    entity_managers:
      italy:
        connection: italy
        mappings:
          MobMindsCoreBundle: ~
          FOSUserBundle: ~
        metadata_cache_driver: apc
        query_cache_driver: apc
        result_cache_driver:
          type:           memcache
          host:           %memcache_host%
          port:           %memcache_port%
          instance_class: Memcache
          class:          Doctrine\Common\Cache\MemcacheCache
      world:
        connection: world
        mappings:
          MobMindsCoreBundle: ~
          FOSUserBundle: ~
        metadata_cache_driver: apc
        query_cache_driver: apc
        result_cache_driver:
          type:           memcache
          host:           %memcache_host%
          port:           %memcache_port%
          instance_class: Memcache
          class:          Doctrine\Common\Cache\MemcacheCache



1. you need to clear apc cache of doctrine. There are 3 ways to do so:
  a. php app/console doctrine:cache:clear-metadata
      if it says :  Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.  
so you need this :
  b. clear by this script:
 
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
$cacheDriver = new \Doctrine\Common\Cache\ApcCache();
$cacheDriver->deleteAll();


in your /web directory.
  c. by a script given by apache cli apc. which can found in their site.

2. other wise it is because you use auto-mapping: enable and then you pass to multi-entities managers, you need to specify the bundles who will use which entity, and this is my problem, i have forgotten to mapping the fosUserBundle with default entity manager, and after i add it , all works well.

        entity_managers:
            default:
                connection:       default
                metadata_cache_driver: apc
                query_cache_driver: apc
                result_cache_driver: apc
                mappings:
                    AcmeUserBundle: ~
                    AcmeBannieresBundle: ~
                    FOSUserBundle: ~

评论

热门博文