Answers.Body: <p>You have some rows in civicrm_job_log that have job_id's that don't exist in civicrm_job. The line just before that is supposed to deal with that but must have failed. I would run <code>UPDATE civicrm_job_log job_log LEFT JOIN civicrm_job job ON job.id = job_log.id SET job_id = NULL WHERE job.id IS NULL</code> manually and see what it says.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-07T16:11:30.933Z
Answers.Text: Thank you, your explanation helps. Here's the sql outcome: UPDATE civicrm_job_log job_log LEFT JOIN civicrm_job job ON job.id = job_log.id SET job_id = NULL WHERE job.id IS NULL
      -> ;
  Query OK, 124 rows affected (0.462 sec)
  Rows matched: 208552  Changed: 124  Warnings: 0
Answers.UserDisplayName: Alan Dixon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-06T15:58:27.923Z
Answers.LastActivityDate: 2023-04-06T15:58:27.923Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>There was a bug in an upgrader step in CiviCRM 5.60 that causes this problem (and also the potential loss of other historical job log data).</p>
  <p>This will be fixed by Civi 5.64.4 (and 5.63-esr) which should come out within the next 24 hours. So if you're version is &lt;5.60 and you can wait until 7 Sep 2023 to upgrade then this should not be a problem.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-06T11:49:11.397Z
Answers.LastActivityDate: 2023-09-06T12:18:31.870Z
Answers.LastEditDate: 2023-09-06T12:18:31.870Z
Answers.UserDisplayName: artfulrobot
Answers.Body: <p>If the other SQL update command doesn't fix it, try this:
  <code>UPDATE civicrm_job_log SET job_id = NULL WHERE job_id NOT IN (SELECT id FROM civicrm_job);</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-06-18T18:12:22.497Z
Answers.Text: This is the one that worked for me, thank you again :D
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-26T15:12:15.650Z
Answers.LastActivityDate: 2023-05-26T15:12:15.650Z
Answers.UserDisplayName: Aidan
Answers.Body: <p>After restoring the CiviCRM database from the backup, I did the following:</p>
  <ol>
  <li><p>Removed all records from <code>civicrm_job_log</code> table by command:
  <code>DELETE FROM civicrm_job_log;</code></p>
  </li>
  <li><p>Re-run the update process from CiviCRM main window, and it finished successfully.</p>
  </li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-26T15:15:06.867Z
Answers.Text: In case it's not obvious to others with the same problem  ... this removes all the log entries relating to scheduled jobs - which is fine if you never look at them, but you might want to try the other SQL fixes first.
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-20T07:36:26.787Z
Answers.LastActivityDate: 2023-04-20T07:36:26.787Z
Answers.UserDisplayName: Nick Kondratiev
Body: <p>During the db upgrade portion of a D7+CiviCRM 5.58.1-&gt;5.60.0 upgrade, I'm hitting the error below. Anyone else? Clues?</p>
  <pre><code>ALTER TABLE civicrm_job_log 
       ADD CONSTRAINT FK_civicrm_job_log_job_id FOREIGN KEY ( `job_id` ) REFERENCES civicrm_job ( id )  ON DELETE SET NULL [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm_iatsdemo_civicrm_ca`.`#sql-1_63`, CONSTRAINT `FK_civicrm_job_log_job_id` FOREIGN KEY (`job_id`) REFERENCES `civicrm_job` (`id`) ON DELETE SET NULL)]
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-05T14:05:25.617Z
Comments.Text: https://chat.civicrm.org/civicrm/pl/5uyter75rtyctr7jfhsx4p1mqr
Comments.UserDisplayName: artfulrobot
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-05T16:40:31.403Z
Comments.Text: That comment above is Rich Lott fixing the problem instead of just working around it. Rich Lott++!!
Comments.UserDisplayName: Alan Dixon
Tags: <upgrade><db-logging>
Title: CiviCRM Upgrade to 5.60, civicrm_job_log foreign key constraint
ThreadText: # CiviCRM Upgrade to 5.60, civicrm_job_log foreign key constraint
  
  (Asked by: username_0 on 2023-04-06)
  
  During the db upgrade portion of a D7+CiviCRM 5.58.1->5.60.0 upgrade, I'm hitting the error below. Anyone else? Clues?
  
  ```
  ALTER TABLE civicrm_job_log 
       ADD CONSTRAINT FK_civicrm_job_log_job_id FOREIGN KEY ( `job_id` ) REFERENCES civicrm_job ( id )  ON DELETE SET NULL [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm_iatsdemo_civicrm_ca`.`#sql-1_63`, CONSTRAINT `FK_civicrm_job_log_job_id` FOREIGN KEY (`job_id`) REFERENCES `civicrm_job` (`id`) ON DELETE SET NULL)]
  
  ```
  
  **Tags:** upgrade, db-logging
  
  > **Comments:**
  > **username_1**: https://chat.civicrm.org/civicrm/pl/5uyter75rtyctr7jfhsx4p1mqr  
  > **username_0**: That comment above is Rich Lott fixing the problem instead of just working around it. Rich Lott++!!  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2023-04-06. Score: 2 | Accepted answer
  
  You have some rows in civicrm\_job\_log that have job\_id's that don't exist in civicrm\_job. The line just before that is supposed to deal with that but must have failed. I would run `UPDATE civicrm_job_log job_log LEFT JOIN civicrm_job job ON job.id = job_log.id SET job_id = NULL WHERE job.id IS NULL` manually and see what it says.
  
  > **Comments:**
  > **username_0**: Thank you, your explanation helps. Here's the sql outcome: UPDATE civicrm_job_log job_log LEFT JOIN civicrm_job job ON job.id = job_log.id SET job_id = NULL WHERE job.id IS NULL     -> ; Query OK, 124 rows affected (0.462 sec) Rows matched: 208552  Changed: 124  Warnings: 0  
  
  ---
  
  ### Answer by username_1 on 2023-09-06. Score: 2
  
  There was a bug in an upgrader step in CiviCRM 5.60 that causes this problem (and also the potential loss of other historical job log data).
  
  This will be fixed by Civi 5.64.4 (and 5.63-esr) which should come out within the next 24 hours. So if you're version is <5.60 and you can wait until 7 Sep 2023 to upgrade then this should not be a problem.
  
  
  ---
  
  ### Answer by username_3 on 2023-05-26. Score: 1
  
  If the other SQL update command doesn't fix it, try this:
  `UPDATE civicrm_job_log SET job_id = NULL WHERE job_id NOT IN (SELECT id FROM civicrm_job);`
  
  > **Comments:**
  > **username_4**: This is the one that worked for me, thank you again :D  
  
  ---
  
  ### Answer by username_5 on 2023-04-20. Score: 0
  
  After restoring the CiviCRM database from the backup, I did the following:
  
  1. Removed all records from `civicrm_job_log` table by command:
     `DELETE FROM civicrm_job_log;`
  2. Re-run the update process from CiviCRM main window, and it finished successfully.
  
  > **Comments:**
  > **username_3**: In case it's not obvious to others with the same problem  ... this removes all the log entries relating to scheduled jobs - which is fine if you never look at them, but you might want to try the other SQL fixes first.  
  
  ---
  
  