nextcloud / nextcloud/mail

DB conversion with "foreign key constraint fails"

Open
#9,284 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. to triage bug
Dominant language
JavaScript
Stars
1k
Forks
348
Avg merge
12h 28m
Merged PRs (30d)
91

Description

Steps to reproduce
  1. Nextcloud instance with PostgreSQL database
  2. Use occ db:convert-type to migrate to MySQL
  3. Fails on oc_mail_attachments table migration
Expected behavior

Database migration should succeed

Actual behavior

Database migration fails with:

 - oc_mail_attachments
 16/16 [============================] 100% < 1 sec/< 1 sec

In ExceptionConverter.php line 58:
An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mydb`.`oc_mail_attachments`, CONSTRAINT `attachment_local_message` FOREIGN KEY (`local_message_id`) REFERENCES `oc_mail_local_messages` (`id`) ON DELETE CASCADE)

In Exception.php line 30:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mydb`.`oc_mail_attachments`, CONSTRAINT `attachment_local_message` FOREIGN KEY (`local_message_id`) REFERENCES `oc_mail_local_messages` (`id`) ON DELETE CASCADE)

In Statement.php line 101:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mydb`.`oc_mail_attachments`, CONSTRAINT `attachment_local_message` FOREIGN KEY (`local_message_id`) REFERENCES `oc_mail_local_messages` (`id`) ON DELETE CASCADE)
Mail app version

3.5.5

Mailserver or service

OVH

Operating system

Debian 11

PHP engine version

PHP 8.2

Web server

Nginx

Database

PostgreSQL

Additional info

Migration to MySQL utf8mb4 database.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the occ db:convert-type entry point and trace the migration of oc_mail_attachments and oc_mail_local_messages; the reported stack trace names ExceptionConverter.php, Exception.php, and Statement.php. Reproduce the PostgreSQL-to-MySQL utf8mb4 conversion and investigate why the foreign key cannot be created; done means the migration completes successfully without violating the attachment relationship.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.