Answers.Body: <p>Looks like the Default organization contact is missing in your database. Try to resave the contact by navigating to CiviCRM >> Administrator >> Communications >> Organization Address and Contact Info </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-23T20:09:46.570Z
Answers.LastActivityDate: 2018-12-23T20:09:46.570Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I've got a 5.8.2 install on Drupal 7.61. When I try to add a new Financial Type, from <code>/civicrm/admin/financial/financialType?reset=1</code>, and click <code>Add Financial Type</code> button, after I enter the info and hit <code>Save</code>, what I see in the GUI is that the spinner spins forever, never returning control to the user. The debug log shows (I've put some hard newlines in for readability):</p>
  
  <pre><code>[to_string] =&gt; [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::exceptionHandler prefix=""
  info="INSERT INTO civicrm_financial_account (name , contact_id , financial_account_type_id , account_type_code , description ,
  is_header_account , is_deductible , is_tax , is_active , is_default )
  VALUES ('New Fin Type' ,  1 ,  3 , 'INC' , 'New Fin Type descript' ,  0 ,  0 ,  0 ,  1 ,  0 )
  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`drupals_uherocrm2`.`civicrm_financial_account`,
  CONSTRAINT `FK_civicrm_financial_account_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE SET NULL)]"]
  </code></pre>
  
  <p>What this seems to show is that it is trying to create a new Financial Account (which I don't really understand because I thought I was only creating a Fin Type), but the Account needs to be linked to an existing Contact, and it's using contact_id=1 as a generic default? But I don't have a Contact with this id=1 in my system.</p>
  
  <p>Any clues what's going on here? The GUI for creating a Fin Type is simple and doesn't given any clues about being linked to a Fin Account, at least not at creation time. Thanks.</p>
  
  <p>Edit: Here is a pastebin of part of my error log, including two examples (which should be equivalent and redundant) of the constraint violation, along with a whole bunch of other junk besides the backtrace, whose value I wasn't sure of, so it was safer to include it. I've edited the file a little to remove my real domain name, just for a little more anonymity. Hope this helps to clarify: <a href="https://paste.pound-python.org/raw/15EPAPfiKEuG7T3in945/" rel="nofollow noreferrer">https://paste.pound-python.org/raw/15EPAPfiKEuG7T3in945/</a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-22T02:08:46.793Z
Comments.Text: I've just realized I can add a contact with id=1 and see if that's a workaround, but would still like to understand these internals better.
Comments.UserDisplayName: Kotodharma
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-23T13:33:41.203Z
Comments.Text: Hmm - this sounds like a bug.  Could you edit your question to include the backtrace from your error log?  This should be easy to fix if we have the backtrace.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-25T00:44:56.753Z
Comments.Text: Thanks @JonG-MegaphoneTech, I have done that.
Comments.UserDisplayName: Kotodharma
Tags: <financial-types><financial-accounts>
Title: Foreign key violation on creating new Financial Type
ThreadText: # Foreign key violation on creating new Financial Type
  
  (Asked by: username_0 on 2018-12-22)
  
  I've got a 5.8.2 install on Drupal 7.61. When I try to add a new Financial Type, from /civicrm/admin/financial/financialType?reset=1, and click Add Financial Type button, after I enter the info and hit Save, what I see in the GUI is that the spinner spins forever, never returning control to the user. The debug log shows (I've put some hard newlines in for readability):
  [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::exceptionHandler prefix=""
  info="INSERT INTO civicrm_financial_account (name , contact_id , financial_account_type_id , account_type_code , description ,
  is_header_account , is_deductible , is_tax , is_active , is_default )
  VALUES ('New Fin Type' ,  1 ,  3 , 'INC' , 'New Fin Type descript' ,  0 ,  0 ,  0 ,  1 ,  0 )
  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`drupals_uherocrm2`.`civicrm_financial_account`,
  CONSTRAINT `FK_civicrm_financial_account_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE SET NULL)]"]
  
  What this seems to show is that it is trying to create a new Financial Account (which I don't really understand because I thought I was only creating a Fin Type), but the Account needs to be linked to an existing Contact, and it's using contact_id=1 as a generic default? But I don't have a Contact with this id=1 in my system.
  Any clues what's going on here? The GUI for creating a Fin Type is simple and doesn't given any clues about being linked to a Fin Account, at least not at creation time. Thanks.
  Edit: Here is a pastebin of part of my error log, including two examples (which should be equivalent and redundant) of the constraint violation, along with a whole bunch of other junk besides the backtrace, whose value I wasn't sure of, so it was safer to include it. I've edited the file a little to remove my real domain name, just for a little more anonymity. Hope this helps to clarify: https://paste.pound-python.org/raw/15EPAPfiKEuG7T3in945/
  
  **Tags:** financial-types, financial-accounts
  
  > **Comments:**
  > **username_0**: I've just realized I can add a contact with id=1 and see if that's a workaround, but would still like to understand these internals better.  
  > **username_1**: Hmm - this sounds like a bug.  Could you edit your question to include the backtrace from your error log?  This should be easy to fix if we have the backtrace.  
  > **username_0**: Thanks @JonG-MegaphoneTech, I have done that.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-12-23. Score: 1
  
  Looks like the Default organization contact is missing in your database. Try to resave the contact by navigating to CiviCRM >> Administrator >> Communications >> Organization Address and Contact Info
  
  
  ---
  
  