Answers.Body: <p>In the database table that links CMS users to CiviCRM contacts, we store a few things:</p>
  
  <ul>
  <li>The CMS user ID (in Drupal's case, the "uid")</li>
  <li>The CiviCRM contact ID</li>
  <li>The email address that both records have in common.</li>
  </ul>
  
  <p>Crucially - all three must be unique!  For instance, you can't have a single CiviCRM contact linked to two Drupal user accounts.</p>
  
  <p>The error you're seeing says, "Hey, Civi tried to create a link between a Drupal user and a Civi contact, but we found that another record in this table already uses that same email address."</p>
  
  <p>Based on that - I'd guess that something about your setup is causing Drupal to try to create two user accounts at once - one connected to the individual and one for the organization.</p>
  
  <p>Without knowing more about your setup, I can't tell you the exact steps to fix it, but hopefully this will make the solution clear to you.</p>
  
  <p>One last thing: In CiviCRM, there's a philosophy of not creating "organization" accounts.  "Organizations" can't log into websites; individuals can.  So if what you're trying to do (it's not 100% clear from the question) is create two logins, consider instead using the relationship permissions to allow the individual to edit the organization instead.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-02T03:57:48.233Z
Answers.Text: Hi, thanks for the quick and thoughtful response. I'm not trying to create an drupal user for the organisation. Just for the person filling out the contribution page on behalf of the organisation. Is this possible. I've tried attaching a New Individual and create drupal account profile but getting issues above.
Answers.UserDisplayName: joewickert
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-01T15:11:45.200Z
Answers.LastActivityDate: 2016-11-01T15:11:45.200Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>Running Drupal 7.43 and civicrm 4.7.12.</p>
  
  <p>We sell memberships to individuals and organisations.</p>
  
  <p>The creation of an Individual works fine. The contact is created and the Drupal account created.</p>
  
  <p>When signing up as an organisation with a name/address/email/create drupal profile, I get the error: </p>
  
  <pre><code>DB Error: already exists.
  </code></pre>
  
  <p>And the fatal error in Drupal logs:</p>
  
  <pre><code>$Fatal Error Details = Array ( [callback] =&gt; Array ( [0] =&gt;  
  CRM_Core_Error [1] =&gt; handle ) [code] =&gt; -5 [message] =&gt; DB Error:   
  already exists [mode] =&gt; 16 [debug_info] =&gt; 
     INSERT INTO civicrm_uf_match (domain_id, uf_id , uf_name , contact_id) 
     VALUES ( 1 , 1229 , 'user@ns9.com' , 2603 ) 
  [nativecode=1062 ** Duplicate entry 'user@ns9.com-1' for key 
  'UI_uf_name_domain_id'] [type] =&gt; DB_Error [user_info] =&gt; INSERT INTO   
  civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 , 
  1229 , 'user@ns9.com' , 2603 ) [nativecode=1062 ** Duplicate entry 
  'user@ns9.com-1' for key 'UI_uf_name_domain_id'] [to_string] =&gt; 
  db_error: 
  message="DB Error: already exists" code=-5 mode=callback      
  callback=CRM_Core_Error::handle prefix="" info="INSERT INTO 
  civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 , 
  1229 , 'user@ns9.com' , 2603 ) [nativecode=1062 ** Duplicate entry 
  'user@ns9.com-1' for key 'UI_uf_name_domain_id']"] )
  </code></pre>
  
  <p>Weird thing is that it seems to work fine.</p>
  
  <ul>
  <li>Organisation is created and given membership.</li>
  <li>Individual is created with relationship to organisation</li>
  <li>Drupal account is created for Individual</li>
  </ul>
  
  <p>But they are just given the error and not logged in.</p>
  
  <p>I can get them to manually create an account after creating membership and link it to their civicrm contact, but it seems like an unneeded extra step for users.</p>
  
  <p>Maybe I need to use civicrm_entity and trigger a rule?
  Thanks</p>
  
Tags: <drupal><civimember><contributions><user-account>
Title: Create Drupal user for contact joining as Organisation
ThreadText: # Create Drupal user for contact joining as Organisation
  
  (Asked by: username_0 on 2016-11-01)
  
  Running Drupal 7.43 and civicrm 4.7.12.
  We sell memberships to individuals and organisations.
  The creation of an Individual works fine. The contact is created and the Drupal account created.
  When signing up as an organisation with a name/address/email/create drupal profile, I get the error: 
  DB Error: already exists.
  
  And the fatal error in Drupal logs:
  $Fatal Error Details = Array ( [callback] => Array ( [0] =>  
  CRM_Core_Error [1] => handle ) [code] => -5 [message] => DB Error:   
  already exists [mode] => 16 [debug_info] => 
     INSERT INTO civicrm_uf_match (domain_id, uf_id , uf_name , contact_id) 
     VALUES ( 1 , 1229 , 'user@ns9.com' , 2603 ) 
  [nativecode=1062 ** Duplicate entry 'user@ns9.com-1' for key 
  'UI_uf_name_domain_id'] [type] => DB_Error [user_info] => INSERT INTO   
  civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 , 
  1229 , 'user@ns9.com' , 2603 ) [nativecode=1062 ** Duplicate entry 
  'user@ns9.com-1' for key 'UI_uf_name_domain_id'] [to_string] => 
  db_error: 
  message="DB Error: already exists" code=-5 mode=callback      
  callback=CRM_Core_Error::handle prefix="" info="INSERT INTO 
  civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 , 
  1229 , 'user@ns9.com' , 2603 ) [nativecode=1062 ** Duplicate entry 
  'user@ns9.com-1' for key 'UI_uf_name_domain_id']"] )
  
  Weird thing is that it seems to work fine.
  
  Organisation is created and given membership.
  Individual is created with relationship to organisation
  Drupal account is created for Individual
  
  But they are just given the error and not logged in.
  I can get them to manually create an account after creating membership and link it to their civicrm contact, but it seems like an unneeded extra step for users.
  Maybe I need to use civicrm_entity and trigger a rule?
  Thanks
  
  **Tags:** drupal, civimember, contributions, user-account
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-01. Score: 2
  
  In the database table that links CMS users to CiviCRM contacts, we store a few things:
  
  * The CMS user ID (in Drupal's case, the "uid")
  * The CiviCRM contact ID
  * The email address that both records have in common.
  
  Crucially - all three must be unique! For instance, you can't have a single CiviCRM contact linked to two Drupal user accounts.
  
  The error you're seeing says, "Hey, Civi tried to create a link between a Drupal user and a Civi contact, but we found that another record in this table already uses that same email address."
  
  Based on that - I'd guess that something about your setup is causing Drupal to try to create two user accounts at once - one connected to the individual and one for the organization.
  
  Without knowing more about your setup, I can't tell you the exact steps to fix it, but hopefully this will make the solution clear to you.
  
  One last thing: In CiviCRM, there's a philosophy of not creating "organization" accounts. "Organizations" can't log into websites; individuals can. So if what you're trying to do (it's not 100% clear from the question) is create two logins, consider instead using the relationship permissions to allow the individual to edit the organization instead.
  
  > **Comments:**
  > **username_0**: Hi, thanks for the quick and thoughtful response. I'm not trying to create an drupal user for the organisation. Just for the person filling out the contribution page on behalf of the organisation. Is this possible. I've tried attaching a New Individual and create drupal account profile but getting issues above.  
  
  ---
  
  