Nextcloud version: 32.0.0
Operating system and version: FreeBSD 14.3-STABLE
Apache version: 2.4.65
PHP version: 8.2.29
Mysql : 8.0.43
Postgresql : 17.6
I’m trying to migrate the nextcloud database from MySQL to PostgreSQL. The command used is:
sudo -E -u www php /usr/local/www/nextcloud/occ db:convert-type --all-apps pgsql nextcloud localhost nextcloud
It converts some tables, and then aborts with this message:
- oc_mail_attachments 0/90 [>---------------------------] 0% < 1 sec/< 1 sec In ExceptionConverter.php line 50: An exception occurred while executing a query: SQLSTATE[23503]: Foreign key violation: 7 ERREUR: une instruction insert ou update sur la table « oc_mail_attachments » viole la contrainte de clé étrangère « attachment_local_message » DETAIL: La clé (local_message_id)=(222) n'est pas présente dans la table « oc_mail_local_messages ». In Exception.php line 24: SQLSTATE[23503]: Foreign key violation: 7 ERREUR: une instruction insert ou update sur la table « oc_mail_attachments » viole la contrainte de clé étrangère « attachment_local_message » DETAIL: La clé (local_message_id)=(222) n'est pas présente dans la table « oc_mail_local_messages ». In Statement.php line 130: SQLSTATE[23503]: Foreign key violation: 7 ERREUR: une instruction insert ou update sur la table « oc_mail_attachments » viole la contrainte de clé étrangère « attachment_local_message » DETAIL: La clé (local_message_id)=(222) n'est pas présente dans la table « oc_mail_local_messages ». db:convert-type [--port PORT] [--password PASSWORD] [--clear-schema] [--all-apps] [--chunk-size CHUNK-SIZE] [--] <type> <username> <hostname> <database>
Remark: the error messages are in french, the first one means “ERROR: an instruction insert or update on the table oc_mail_attachments violates the foreign key constraint”, and the second message means “the foreign key (local_message_id)=(222) does not exist in the table oc_mail_local_messages.
Questions: should I deactivate the foreign keys before the migration and reactivate after it?
Or is it better to re-order the instructions of the scripts?
Which is the usual solution for this error?