Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Won't Fix
-
Affects Version/s: 4.3.1
-
Fix Version/s: 4.3.5
-
Component/s: None
-
Labels:None
Description
When upgrading a site I got the following error:
ALTER TABLE civicrm_membership_type DROP FOREIGN KEY FK_civicrm_membership_autorenewal_msg_id [nativecode=1025 ** Error on rename of './ptppiglet_0/civicrm_membership_type' to './ptppiglet_0/#sql2-4f9-1e80' (errno: 152)]
This seems related to this comment: http://issues.civicrm.org/jira/browse/CRM-11260?focusedCommentId=46841&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-46841
In our case, we have an index in the civicrm_membership_type called FK_civicrm_membership_autorenewal_msg_id but there is no corresponding foreign key.
In investigating, I noticed that the function CRM_Core_DAO::checkConstraintExists function doesn't actually check if the constraint exists. It checks if there is any text in the entire CREATE TABLE statement that matches the name of the foreign constraint. There is a more reliable way to check for constraints (using INFORMATION_SCHEMA.TABLE_CONSTRAINTS).
I have a patch for that... but then I got another failure because CRM_Upgrade_Incremental_php_FourThree::task_4_3_alpha1_checkDBConstraints, on line 775, allows the constraint deletion code to move forward, even if we have just demonstrated that the constraint doesn't exist.