2

After updating from 5.8.2 to 5.9.0, anonymous users suddenly get the above error when trying to register for an event.

Anyone a good hint how to resolve that? Thanks

Debug log shows

Datenbank-Errorcode: Cannot add or update a child row: a foreign key constraint fails (db_local.civicrm_acl_contact_cache, CONSTRAINT FK_civicrm_acl_contact_cache_user_id FOREIGN KEY (user_id) REFERENCES civicrm_contact (id) ON DELETE CASCADE), 1452 Zusätzliche Details:

Array ( [callback] => Array ( [0] => CRM_Core_Error [1] => handle )

[code] => -3
[message] => DB Error: constraint violation
[mode] => 16
[debug_info] => INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation ) VALUES(0, 0, 'View') [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`db_local`.`civicrm_acl_contact_cache`, CONSTRAINT `FK_civicrm_acl_contact_cache_user_id` FOREIGN KEY (`user_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
[type] => DB_Error
[user_info] => INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation ) VALUES(0, 0, 'View') [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`db_local`.`civicrm_acl_contact_cache`, CONSTRAINT `FK_civicrm_acl_contact_cache_user_id` FOREIGN KEY (`user_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
[to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation ) VALUES(0, 0, 'View') [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`db_local`.`civicrm_acl_contact_cache`, CONSTRAINT `FK_civicrm_acl_contact_cache_user_id` FOREIGN KEY (`user_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]"]

)

4
  • Are you able to replicate this issue on a sandbox site?
    – davejenx
    Commented Jan 10, 2019 at 15:49
  • Do you have ACL enabled on site? Commented Jan 10, 2019 at 16:22
  • I use only the Wordpress permission management and have no further ACL enabled. Commented Jan 10, 2019 at 16:27
  • I have the same problem with 5.8.x to 5.9 upgrade on a contribution page for anon users (Joomla). Error: Database Error Code: Cannot add or update a child row: a foreign key constraint fails (zzz.civicrm_acl_contact_cache, CONSTRAINT FK_civicrm_acl_contact_cache_user_id FOREIGN KEY (user_id) REFERENCES civicrm_contact (id) ON DELETE CASCADE), 1452 Additional Details: Array ( [callback] => Array ( [0] => CRM_Core_Error [1] => handle ) [code] => -3 [message] => DB Error: constraint violation [mode] => 16 [debug_info] => INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, ope
    – Nic
    Commented Jan 16, 2019 at 19:26

4 Answers 4

2

I could solve the problem... I had disabled the Mail module of CiviCRM as I do yet not use it. After reenabling it, the error was gone. Looks like that even disabled modules leave remnants in the database causing possible trouble.

2

This pull request seems relevant to the database error you encountered: (dev/core#660) Address regression whereby Anonymous users can no longer register for an event if they have ACLs to see a contact. This fixes an issue that was I believe introduced in Civi 5.9.0 and fixed in 5.9.1 .

See also related issue Fatal DB Error: already exists on event registration/contribution pages when profile has user creation.

1
  • These issues are cousins - but one affects the civicrm_uf_match table, the other affects civicrm_acl_contact_cache. My answer below addresses it. Commented Dec 29, 2023 at 21:16
0

We recently upgraded a CiviCRM installation from 4.6 to 5.9.0 and encountered the same issue when trying to register for a membership (contribution page) as anonymous user.

Disabling/enabling the CiviCRM Mail Component didn't fix this.

I removed the foreign keys in the database as a temporary fix:

alter table civicrm_acl_contact_cache drop foreign key FK_civicrm_acl_contact_cache_user_id alter table civicrm_acl_contact_cache drop foreign key FK_civicrm_acl_contact_cache_contact_id

0

I encountered this when I had a particular customization in place, but it revealed what I think is the core issue.

This error occurs when you have "view my contact" and/or "edit my contact" permission on the anonymous user - who, by definition, does not have a contact.

I'm submitting a patch, so hopefully this is a non-issue in CiviCRM 5.70+ or so, but you can fix it now by changing your CMS's user permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.