Fosuserbundle: 'Duplicate definition of column 'username' on entity' overriding model in 2.0.*

Created on 27 Feb 2015  路  4Comments  路  Source: FriendsOfSymfony/FOSUserBundle

Hi,

I've previously successfully overridden the mapping of the orm user by redefining the whole mapping in my own user class and extending the user model (not entity) using userbundle 1.3.*.

I've recently started up a new project where I wanted to do this again and grabbed my classes from the previous project. In composer I've added userbundle 2.0.*@dev as my dependancy.
Now when clearing cache/validating schema I get the infamous 'Duplicate definition of column 'username' on entity' error for my own User class.

Here's a gist with my classes and configs,
https://gist.github.com/philrennie/7bea08dc45a8427f8140

I'm guessing this may be due to userbundle registering compiler and mapping passes, I saw this noted in the docs, looked at the code for it and then went to look at the commit where it changed
https://github.com/FriendsOfSymfony/FOSUserBundle/commit/6290fd7b6278706327f21aae55844e7d23be0008
and there's a note right at the end from @dbu that says this shouldn't happen, but I appear to be triggering it.

I've stared at this for a few hours now, so if someone could either point out where I've made a mistake or what I'm doing wrong I'd appreciate it.

Most helpful comment

Hi @philrennie,

I have the same issue when extending from use FOS\UserBundle\Model\User. You can use @ORM\AttributeOverrides to override the default settings.

  • Remove column definition for username
  • Add @ORM\AttributeOverrides to User or BaseUser class

Example:

 /**
 * ...
 * @AttributeOverrides({
 *      @AttributeOverride(name="username",
 *          column=@Column(
 *              name     = "username1234567",
 *              nullable = false,
 *              unique   = true,
 *              length   = 123
 *          )
 *      )
 * })

All 4 comments

strange, i don't know why this is happening. a few questions/ideas though:

  • Should BaseUser not have a @MappedSuperclass annotation? I am not 100% sure - i would have expected the BaseClass to not be seen by doctrine at all.
  • Do you retain anything at all from the FOSUserBundle model? otherwise you could simply stop extending it
  • If you would use xml/yml mapping for your entities, you would not need to re-define the fields but could just redefine the mapping.

Hi @philrennie,

I have the same issue when extending from use FOS\UserBundle\Model\User. You can use @ORM\AttributeOverrides to override the default settings.

  • Remove column definition for username
  • Add @ORM\AttributeOverrides to User or BaseUser class

Example:

 /**
 * ...
 * @AttributeOverrides({
 *      @AttributeOverride(name="username",
 *          column=@Column(
 *              name     = "username1234567",
 *              nullable = false,
 *              unique   = true,
 *              length   = 123
 *          )
 *      )
 * })

Hi @estahn,

When I first raised this I was moving at speed and didn't manage to get the attributeoverrides working, I should revisit it in the near future.
What I did end up doing was setting FUB to use the 'custom' db_driver type (so no mapping was pulled in by the compiler pass) and implementing a super stripped down usermanager and userprovider to support them, which let me go wild with mapping a custom user entity (I was moving roles into the DB)

I created a gist of what I knocked up in case it's useful to anyone
https://gist.github.com/philrennie/45918e42147c3db7cca8

This is ancient and out of date so closing it off to be tidy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gogoseo picture gogoseo  路  6Comments

flik picture flik  路  4Comments

kironet picture kironet  路  4Comments

soullivaneuh picture soullivaneuh  路  6Comments

pmpr-ir picture pmpr-ir  路  3Comments