Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrecognized field: usernameCanonical #373

Closed
FMaz008 opened this issue Oct 19, 2011 · 9 comments
Closed

Unrecognized field: usernameCanonical #373

FMaz008 opened this issue Oct 19, 2011 · 9 comments

Comments

@FMaz008
Copy link

FMaz008 commented Oct 19, 2011

( Note: I've read issue #351 and #230 , and I'm using Symfony 2.0.4 )
Hi !

The login form is displayed correctly, but when I try to login, I get the error

Promote command : "Unrecognized field: usernameCanonical"

Here's my app/config/config.yml file:

imports:
    - { resource: parameters.ini }
    - { resource: security.yml }

framework:
    #esi:             ~
    translator:      { fallback: %locale% }
    secret:          %secret%
    charset:         UTF-8
    router:          { resource: "%kernel.root_dir%/config/routing.yml" }
    form:            true
    csrf_protection: true
    validation:      { enable_annotations: true }
    templating:      { engines: ['twig'] } #assets_version: SomeVersionScheme
    session:
        default_locale: %locale%
        auto_start:     true

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        cssrewrite: ~
        # closure:
        #     jar: %kernel.root_dir%/java/compiler.jar
        # yui_css:
        #     jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%

jms_security_extra:
    secure_controllers:  true
    secure_all_services: false

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb'
    firewall_name: main
    use_listener: false
    user_class: IT\Bundle\UserBundle\Entity\User


jms_i18n_routing:
    default_locale: en
    locales: [fr, en_CA, en, es]
    strategy: prefix

My custom user entity:

<?php

namespace IT\Bundle\UserBundle\Entity;

use FOS\UserBundle\Document\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

My bundle file:

<?php

namespace IT\Bundle\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ITUserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

A few day ago, when I've followed the tutorial installation, it was working well. Since then, I've installed JMSi18nRoutingBundle, and it seem that thing doesn't work anymore. If I run doctrine:schema:update --force, I now have the following output, making me thing that their's a problem with the mapping:

Symfony > doctrine:schema:update --dump-sql
DROP INDEX UNIQ_957A647992FC23A8 ON fos_user;
DROP INDEX UNIQ_957A6479A0D96FBF ON fos_user;
ALTER TABLE fos_user DROP username, DROP username_canonical, DROP email, DROP email_canonical, DROP enabled, DROP algorithm, DROP salt, DROP password, DROP last_login, DROP locked, DROP expired, DROP expires_at, DROP confirmation_token, DROP password_requested_at, DROP roles, DROP credentials_expired, DROP credentials_expire_at

Any idea ?
Ps.: Would be great to have error message that give some hint about solutions ... No trace, no file, no line, it's hard to understand at first...

Thanks

@stof
Copy link
Member

stof commented Oct 19, 2011

it seems like the mapping for FOSUserBundle is not found by Doctrine. Is FOSUserBundle registered propertly in your kernel ?

@FMaz008
Copy link
Author

FMaz008 commented Oct 19, 2011

Wow that's fast !

So far, my AppKernel.php look's ok ... I think:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new IT\OSBundle\ITOSBundle(),
            new IT\Bundle\UserBundle\ITUserBundle(),
            new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

And here's the autoloader.php :

<?php

use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    'Symfony'          => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
    'Sensio'           => __DIR__.'/../vendor/bundles',
    'JMS'              => __DIR__.'/../vendor/bundles',
    'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
    'Doctrine\\DBAL'   => __DIR__.'/../vendor/doctrine-dbal/lib',
    'Doctrine'         => __DIR__.'/../vendor/doctrine/lib',
    'Monolog'          => __DIR__.'/../vendor/monolog/src',
    'Assetic'          => __DIR__.'/../vendor/assetic/src',
    'Metadata'         => __DIR__.'/../vendor/metadata/src',
    'FOS'              => __DIR__.'/../vendor/bundles',
));
$loader->registerPrefixes(array(
    'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
    'Twig_'            => __DIR__.'/../vendor/twig/lib',
));

// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
}

$loader->registerNamespaceFallbacks(array(
    __DIR__.'/../src',
));
$loader->register();

AnnotationRegistry::registerLoader(function($class) use ($loader) {
    $loader->loadClass($class);
    return class_exists($class, false);
});
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');

// Swiftmailer needs a special autoloader to allow
// the lazy loading of the init file (which is expensive)
require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php';
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');

@FMaz008
Copy link
Author

FMaz008 commented Oct 19, 2011

Just found the solution, I was extending FOS\UserBundle\Document\User, and not FOS\UserBundle\Entity\User.
I edited the use statement and everything works again.

Thanks for the help, and I hope this will help someone else !

@FMaz008 FMaz008 closed this as completed Oct 19, 2011
@topwebstudio
Copy link

For anyone having similar issues use app/console doctrine:mapping:info
Make sure all of your mappings are there, for example in production mode when you don't want auto generating
proxy classes:

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                metadata_cache_driver: apc
                result_cache_driver: apc
                query_cache_driver: apc
                connection: default
                mappings:
                   AcmeDemoBundle: ~
                   FOSUserBundle: ~
                   FOSCommentBundle: ~

@morpheous
Copy link

Thanks. Was very useful. Helped save me hours.

@dr1ss
Copy link

dr1ss commented Apr 23, 2013

Just an additionnal info here...
If you are using apc as the cache driver and u added FOSUserBundle because you didn't at first, make sure to manually clear apc (or restart the webserver) because the apc cache is not cleared with the console cache:clear

@stof
Copy link
Member

stof commented Apr 23, 2013

@dr1ss This is a common pitfall with APC: the CLI and the webserver are using separate APC caches

@dr1ss
Copy link

dr1ss commented Apr 23, 2013

Oh ok I thought APC clearing is not even done from the console.. good to know

@kvdnberg
Copy link

Thanks Topweb, I switched from one entity manager to two and dropped the line "auto mapping" because that's incompatible but forgot to add FOSUserBundle to the mappings, which resulted in the base FOSUser fields to be dropped. Added it back and now all is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants