Answers.Body: <p>This pull request seems relevant to the database error you encountered: <a href="https://github.com/civicrm/civicrm-core/pull/13451" rel="nofollow noreferrer">(dev/core#660) Address regression whereby Anonymous users can no longer register for an event if they have ACLs to see a contact</a>. This fixes an issue that was I believe introduced in Civi 5.9.0 and fixed in 5.9.1 .</p>
  
  <p>See also related issue <a href="https://lab.civicrm.org/dev/core/issues/660" rel="nofollow noreferrer">Fatal DB Error: already exists on event registration/contribution pages when profile has user creation</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-29T21:16:55.600Z
Answers.Text: These issues are cousins - but one affects the `civicrm_uf_match` table, the other affects `civicrm_acl_contact_cache`.  My answer below addresses it.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-17T11:22:42.827Z
Answers.LastActivityDate: 2019-01-17T11:22:42.827Z
Answers.UserDisplayName: davejenx
Answers.Body: <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-10T16:29:00.303Z
Answers.LastActivityDate: 2019-01-10T16:29:00.303Z
Answers.UserDisplayName: Andreas Klein
Answers.Body: <p>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.</p>
  
  <p>Disabling/enabling the CiviCRM Mail Component didn't fix this.</p>
  
  <p>I removed the foreign keys in the database as a temporary fix:</p>
  
  <p><code>alter table civicrm_acl_contact_cache drop foreign key FK_civicrm_acl_contact_cache_user_id</code>
  <code>alter table civicrm_acl_contact_cache drop foreign key FK_civicrm_acl_contact_cache_contact_id</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-17T16:17:30.670Z
Answers.LastActivityDate: 2019-01-17T16:17:30.670Z
Answers.UserDisplayName: Wouter H.
Answers.Body: <p>I encountered this when I had a particular customization in place, but it revealed what I think is the core issue.</p>
  <p>This error occurs when you have &quot;view my contact&quot; and/or &quot;edit my contact&quot; permission on the anonymous user - who, by definition, does not have a contact.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-29T21:16:24.157Z
Answers.LastActivityDate: 2023-12-29T22:13:18.907Z
Answers.LastEditDate: 2023-12-29T22:13:18.907Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>After updating from 5.8.2 to 5.9.0, anonymous users suddenly get the above error when trying to register for an event.</p>
  
  <p>Anyone a good hint how to resolve that? Thanks</p>
  
  <p>Debug log shows</p>
  
  <p>Datenbank-Errorcode: Cannot add or update a child row: a foreign key constraint fails (<code>db_local</code>.<code>civicrm_acl_contact_cache</code>, CONSTRAINT <code>FK_civicrm_acl_contact_cache_user_id</code> FOREIGN KEY (<code>user_id</code>) REFERENCES <code>civicrm_contact</code> (<code>id</code>) ON DELETE CASCADE), 1452
  Zusätzliche Details:</p>
  
  <p>Array
  (
      [callback] => Array
          (
              [0] => CRM_Core_Error
              [1] => handle
          )</p>
  
  <pre><code>[code] =&gt; -3
  [message] =&gt; DB Error: constraint violation
  [mode] =&gt; 16
  [debug_info] =&gt; 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] =&gt; DB_Error
  [user_info] =&gt; 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] =&gt; [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)]"]
  </code></pre>
  
  <p>)</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-10T15:49:52.153Z
Comments.Text: Are you able to replicate this issue on a [sandbox site](https://civicrm.org/sandboxes)?
Comments.UserDisplayName: davejenx
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-10T16:22:17.687Z
Comments.Text: Do you have ACL enabled on site?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-10T16:27:41.693Z
Comments.Text: I use only the Wordpress permission management and have no further ACL enabled.
Comments.UserDisplayName: Andreas Klein
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-16T19:26:25.023Z
Comments.Text: 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
Comments.UserDisplayName: Nic
Tags: <error><database>
Title: DB Error: constraint violation on anonymous user event registration after 5.8.2 -> 5.9.0 update
ThreadText: # DB Error: constraint violation on anonymous user event registration after 5.8.2 -> 5.9.0 update
  
  (Asked by: username_0 on 2019-01-10)
  
  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)]"]
  
  ```
  
  )
  
  **Tags:** error, database
  
  > **Comments:**
  > **username_1**: Are you able to replicate this issue on a [sandbox site](https://civicrm.org/sandboxes)?  
  > **username_2**: Do you have ACL enabled on site?  
  > **username_0**: I use only the Wordpress permission management and have no further ACL enabled.  
  > **username_3**: 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  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2019-01-17. Score: 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](https://github.com/civicrm/civicrm-core/pull/13451). 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](https://lab.civicrm.org/dev/core/issues/660).
  
  > **Comments:**
  > **username_4**: These issues are cousins - but one affects the `civicrm_uf_match` table, the other affects `civicrm_acl_contact_cache`.  My answer below addresses it.  
  
  ---
  
  ### Answer by username_0 on 2019-01-10. Score: 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.
  
  
  ---
  
  ### Answer by username_5 on 2019-01-17. Score: 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`
  
  
  ---
  
  ### Answer by username_4 on 2023-12-29. Score: 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.
  
  
  ---
  
  