Update User Profile with Plugin I'm trying to create a plugin to create/update users' profile data. I figured out how to create a user but updating... not so much.

Here is the code I'm using:

$user = craft()-&gt;userSession-&gt;getUser();
$user-&gt;setContent(array('middleName' =&gt; "Dave"));
craft()-&gt;users-&gt;saveUser($user);


From what I understand the "saveUser" method is used for both creating and updating user data. Whenever I run the code I get the following error:

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-en_us' for key 'craft_content_elementId_locale_unq_idx'

If "saveUser" is truly used for creating and updating what am I doing wrong?
I'm not sure if this is causing your error, but it's recommended to use setContentFromPost() or getContent()->setAttributes() so that craft has a chance to prep the field values, as discussed in this answer, setContent() vs $entry->getContent()->foo, and What is getContent()?.

$user = craft()-&gt;userSession-&gt;getUser();
$user-&gt;getContent()-&gt;setAttributes(array(
    'middleName' =&gt; "Dave",
));
craft()-&gt;users-&gt;saveUser($user);


Although with that error it's possible that something else is going on in your plugin.