Answers.Body: <p>There are orphan data in civicrm_mailing_event_queue table. Below query should return you the count</p>
  <pre><code>SELECT COUNT(*) 
  FROM civicrm_mailing_event_queue q 
    LEFT JOIN civicrm_mailing_job j 
        ON j.id = q.job_id 
  WHERE j.id IS NULL;
  </code></pre>
  <p>To delete you can use</p>
  <pre><code>DELETE q.*
  FROM civicrm_mailing_event_queue q 
    LEFT JOIN civicrm_mailing_job j 
      ON j.id = q.job_id 
  WHERE j.id IS NULL;
  </code></pre>
  <p>HTH</p>
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-14T01:21:42.670Z
Answers.LastActivityDate: 2024-03-14T01:21:42.670Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>Upgrading CiviCRM to 5.70.2 from 5.64.0 fails with the below error. Any pointers are appreciated.</p>
  <pre><code>DB Error: constraint violation                                                                                 
    sql                                                                                                                                                        
    user info                                                                                                                                                  
          ALTER TABLE `civicrm_mailing_event_queue`                                                                                                            
          ADD CONSTRAINT `FK_civicrm_mailing_event_queue_job_id`                                                                                               
          FOREIGN KEY (`job_id`)                                                                                                                               
          REFERENCES `civicrm_mailing_job`(`id`) ON DELETE SET NULL                                                                                            
         [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`mif10_civicrm`.`#sql-4f687h_5fuvo`, CONSTRAINT `FK_civicrm_ma  
    iling_event_queue_job_id` FOREIGN KEY (`job_id`) REFERENCES `civicrm_mailing_job` (`id`) ON DELETE SET NULL)]                                              
    debug info DB Error: constraint violation                                                                                                                  
    debug info                                                                                                                                                 
          ALTER TABLE `civicrm_mailing_event_queue`                                                                                                            
          ADD CONSTRAINT `FK_civicrm_mailing_event_queue_job_id`                                                                                               
          FOREIGN KEY (`job_id`)                                                                                                                               
          REFERENCES `civicrm_mailing_job`(`id`) ON DELETE SET NULL                                                                                            
         [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`mif10_civicrm`.`#sql-4f687h_5fuvo`, CONSTRAINT `FK_civicrm_ma  
    iling_event_queue_job_id` FOREIGN KEY (`job_id`) REFERENCES `civicrm_mailing_job` (`id`) ON DELETE SET NULL)] 
  </code></pre>
  
Tags: <upgrade>
Title: Upgrade to 5.70.2 fails with DB error
ThreadText: # Upgrade to 5.70.2 fails with DB error
  
  (Asked by: username_0 on 2024-03-14)
  
  Upgrading CiviCRM to 5.70.2 from 5.64.0 fails with the below error. Any pointers are appreciated.
  
  ```
  DB Error: constraint violation                                                                                 
    sql                                                                                                                                                        
    user info                                                                                                                                                  
          ALTER TABLE `civicrm_mailing_event_queue`                                                                                                            
          ADD CONSTRAINT `FK_civicrm_mailing_event_queue_job_id`                                                                                               
          FOREIGN KEY (`job_id`)                                                                                                                               
          REFERENCES `civicrm_mailing_job`(`id`) ON DELETE SET NULL                                                                                            
         [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`mif10_civicrm`.`#sql-4f687h_5fuvo`, CONSTRAINT `FK_civicrm_ma  
    iling_event_queue_job_id` FOREIGN KEY (`job_id`) REFERENCES `civicrm_mailing_job` (`id`) ON DELETE SET NULL)]                                              
    debug info DB Error: constraint violation                                                                                                                  
    debug info                                                                                                                                                 
          ALTER TABLE `civicrm_mailing_event_queue`                                                                                                            
          ADD CONSTRAINT `FK_civicrm_mailing_event_queue_job_id`                                                                                               
          FOREIGN KEY (`job_id`)                                                                                                                               
          REFERENCES `civicrm_mailing_job`(`id`) ON DELETE SET NULL                                                                                            
         [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`mif10_civicrm`.`#sql-4f687h_5fuvo`, CONSTRAINT `FK_civicrm_ma  
    iling_event_queue_job_id` FOREIGN KEY (`job_id`) REFERENCES `civicrm_mailing_job` (`id`) ON DELETE SET NULL)] 
  
  ```
  
  **Tags:** upgrade
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-03-14. Score: 2
  
  There are orphan data in civicrm\_mailing\_event\_queue table. Below query should return you the count
  
  ```
  SELECT COUNT(*) 
  FROM civicrm_mailing_event_queue q 
    LEFT JOIN civicrm_mailing_job j 
        ON j.id = q.job_id 
  WHERE j.id IS NULL;
  
  ```
  
  To delete you can use
  
  ```
  DELETE q.*
  FROM civicrm_mailing_event_queue q 
    LEFT JOIN civicrm_mailing_job j 
      ON j.id = q.job_id 
  WHERE j.id IS NULL;
  
  ```
  
  HTH
  
  username_1
  
  
  ---
  
  