Answers.Body: <p>Do you know how to manually run SQL queries in MySQL? You can use <a href="https://www.phpmyadmin.net/" rel="nofollow noreferrer">phpMyAdmin</a> or the <a href="https://dev.mysql.com/doc/refman/8.0/en/mysql.html" rel="nofollow noreferrer">command line</a> or some other control panel tool that might be installed in your hosting.</p>
  <p>It's telling you to do it manually because the upgrade checked that you have a lot of activities in your database so it might take a long time to run. Optionally make a backup first, and then the query you want to run is</p>
  <ul>
  <li><code>ALTER TABLE civicrm_activity DROP FOREIGN KEY FK_civicrm_activity_original_id;</code></li>
  <li><code>ALTER TABLE civicrm_activity ADD CONSTRAINT FK_civicrm_activity_original_id FOREIGN KEY (original_id) REFERENCES civicrm_activity (id) ON DELETE SET NULL;</code></li>
  </ul>
  <p>Then there are some optional things you can do depending on what strategy you want to use for handling deprecated CiviCase activity revisions. The easiest is run <code>DELETE FROM civicrm_activity WHERE is_current_revision = 0;</code>, but DON'T do that before running the above queries.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-07T16:05:06.957Z
Answers.Text: I've also updated the lab snippet a bit. I didn't notice how much the upgrade message wording was changed at the last minute.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-08T05:22:33.157Z
Answers.Text: Thank you for this fast and helpful response!
Answers.UserDisplayName: Tobias Krause
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-07T14:43:47.643Z
Answers.LastActivityDate: 2023-02-07T14:43:47.643Z
Answers.UserDisplayName: Demerit
Body: <p>After updating CiviCRM I get the above warning. The Link added to the warning &quot;Learn how to fix this&quot; leads to this page <a href="https://lab.civicrm.org/-/snippets/85" rel="nofollow noreferrer">https://lab.civicrm.org/-/snippets/85</a> which does not describe how I remove the incorrect constraint - at least I don't understand from this how to do it. Can somebody help me?</p>
  
Tags: <activities><activity>
Title: The table civicrm_activity includes an incorrect constraint
ThreadText: # The table civicrm_activity includes an incorrect constraint
  
  (Asked by: username_0 on 2023-02-07)
  
  After updating CiviCRM I get the above warning. The Link added to the warning "Learn how to fix this" leads to this page <https://lab.civicrm.org/-/snippets/85> which does not describe how I remove the incorrect constraint - at least I don't understand from this how to do it. Can somebody help me?
  
  **Tags:** activities, activity
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-02-07. Score: 2 | Accepted answer
  
  Do you know how to manually run SQL queries in MySQL? You can use [phpMyAdmin](https://www.phpmyadmin.net/) or the [command line](https://dev.mysql.com/doc/refman/8.0/en/mysql.html) or some other control panel tool that might be installed in your hosting.
  
  It's telling you to do it manually because the upgrade checked that you have a lot of activities in your database so it might take a long time to run. Optionally make a backup first, and then the query you want to run is
  
  * `ALTER TABLE civicrm_activity DROP FOREIGN KEY FK_civicrm_activity_original_id;`
  * `ALTER TABLE civicrm_activity ADD CONSTRAINT FK_civicrm_activity_original_id FOREIGN KEY (original_id) REFERENCES civicrm_activity (id) ON DELETE SET NULL;`
  
  Then there are some optional things you can do depending on what strategy you want to use for handling deprecated CiviCase activity revisions. The easiest is run `DELETE FROM civicrm_activity WHERE is_current_revision = 0;`, but DON'T do that before running the above queries.
  
  > **Comments:**
  > **username_1**: I've also updated the lab snippet a bit. I didn't notice how much the upgrade message wording was changed at the last minute.  
  > **username_0**: Thank you for this fast and helpful response!  
  
  ---
  
  