Answers.Body: <p>Strange, we had an issue on 4.6.24 just now.</p>
  
  <p>The CiviCRM log file stated: -</p>
  
  <pre><code>DB Error: constraint violation
  </code></pre>
  
  <p>The debug information should give you the MySQL table name. For some reason, a custom table (civicrm_value_tablename_id) was linked by foreign key (entity_id) to the wrong table. In my case, it was the civicrm_event table, whereas it should have been to the civicrm_participant table.</p>
  
  <p>My solution was to truncate (empty) the civicrm_value_tablename_id table, remove the incorrect foreign key, then add the correct foreign key.</p>
  
  <p>Strange though that I had to do this manually as the CiviCRM custom data set screen showed that the Custom Data set in question is 'Used for' (or extends Participants).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-27T08:42:54.457Z
Answers.LastActivityDate: 2017-09-27T08:42:54.457Z
Answers.UserDisplayName: Jon-man
Body: <p>Help! I just upgraded Civi from 4.7.3 to 4.7.7, but my host timed out during the DB upgrade and it was unable to complete. So I restored a backup of the database and was going to try again, but now every time I do anything with Civi, it gives me a DB Error: constraint violation.</p>
  
  <p>I can't access any of Civi's backend now; it all gives me the same error. And when I try to run the upgrade script, it gives me the error after I click upgrade.</p>
  
  <p>Is there anything I can do? Is my entire Database and my backup worthless now??</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-17T18:11:04.637Z
Comments.Text: Begin by looking at the CiviCRM log files (https://wiki.civicrm.org/confluence/display/CRMDOC/Debugging+for+developers#Debuggingfordevelopers-Logfiles). That should provide a clue regarding the nature of the constraint violation. It may be something you can fix manually and then proceed with the upgrade.
Comments.UserDisplayName: lcdservices
Tags: <upgrade><backups>
Title: DB Error: constraint violation
ThreadText: # DB Error: constraint violation
  
  (Asked by: username_0 on 2016-05-17)
  
  Help! I just upgraded Civi from 4.7.3 to 4.7.7, but my host timed out during the DB upgrade and it was unable to complete. So I restored a backup of the database and was going to try again, but now every time I do anything with Civi, it gives me a DB Error: constraint violation.
  
  I can't access any of Civi's backend now; it all gives me the same error. And when I try to run the upgrade script, it gives me the error after I click upgrade.
  
  Is there anything I can do? Is my entire Database and my backup worthless now??
  
  **Tags:** upgrade, backups
  
  > **Comments:**
  > **username_1**: Begin by looking at the CiviCRM log files (https://wiki.civicrm.org/confluence/display/CRMDOC/Debugging+for+developers#Debuggingfordevelopers-Logfiles). That should provide a clue regarding the nature of the constraint violation. It may be something you can fix manually and then proceed with the upgrade.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-09-27. Score: 1
  
  Strange, we had an issue on 4.6.24 just now.
  The CiviCRM log file stated: -
  DB Error: constraint violation
  
  The debug information should give you the MySQL table name. For some reason, a custom table (civicrm_value_tablename_id) was linked by foreign key (entity_id) to the wrong table. In my case, it was the civicrm_event table, whereas it should have been to the civicrm_participant table.
  My solution was to truncate (empty) the civicrm_value_tablename_id table, remove the incorrect foreign key, then add the correct foreign key.
  Strange though that I had to do this manually as the CiviCRM custom data set screen showed that the Custom Data set in question is 'Used for' (or extends Participants).
  
  
  ---
  
  