OJS 3.4 – Error while importing published issue to another portal (Foreign key constraint: primary_contact_id)

Hello,

I am trying to migrate a fully published issue from one OJS portal to another OJS portal.

Environment

  • OJS Version: 3.4.0-9 (same version on both source and destination portals)
  • Database: MySQL
  • Migration type: Import by Native XML Plugin

Error encountered during import

During the import of the issue, the process fails with the following database error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`ojs34`.`publications`, CONSTRAINT `publications_primary_contact_id` FOREIGN KEY (`primary_contact_id`) REFERENCES `authors` (`author_id`) ON DELETE SET NULL) (SQL: update `publications` set `access_status` = 0, `date_published` = 2025-06-20, `last_modified` = 2026-01-15 09:20:16, `primary_contact_id` = 0, `section_id` = 264, `seq` = 1, `submission_id` = 174357, `status` = 3, `url_path` = ?, `version` = 1, `doi_id` = 20827 where `publication_id` = 151863)
  • The error is caused by primary_contact_id = 0
  • In the destination database, there is no author with author_id = 0

Any guidance, best practices, or references would be highly appreciated.

Hi @shantanusingh!

I see room for failure on the code, do you have a sample XML to provide? It can be with anonymized data, I’d just like to see the content of the <authors> node.

Best,
Jonas Raoni

Hi @jonasraoni Thanks for reply

Please refer to this link for the XML file.

Hi @shantanusingh,

I could import this XML without any issues on my environment, this leads me to believe you might be having problems with the charset/collation. Are you using the charset utf8mb4?

Do you see more error messages on the error log appearning before this one that I can see on the screenshot?

Best,
Jonas Raoni

Hi @jonasraoni

After running the SQL query SHOW CREATE DATABASE database; the result shows /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */

Just I have tried to new setup but same issue appeared.

No error log generated for this. Only show below error on OJS application.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`ojs3409`.`publications`, CONSTRAINT `publications_primary_contact_id` FOREIGN KEY (`primary_contact_id`) REFERENCES `authors` (`author_id`) ON DELETE SET NULL) (SQL: update `publications` set `access_status` = 0, `date_published` = 2025-06-20, `last_modified` = 2026-04-09 13:36:20, `primary_contact_id` = 0, `section_id` = 40, `seq` = 1, `submission_id` = 11, `status` = 3, `url_path` = ?, `version` = 1, `doi_id` = 10 where `publication_id` = 11)

This is the charset/collation of the database, MySQL allows you to have tables with different charsets/collations too, you can run this query to check if this is your case (just replace the NAME_OF_YOUR_DATABASE by your database name):

SELECT table_name, table_collation
FROM information_schema.tables
WHERE table_schema = ‘NAME_OF_YOUR_DATABASE’
AND table_collation != ‘utf8mb4_0900_ai_ci’;

If everything is ok at this point and you have no other errors on the log, then it will be require some debugging :slight_smile:

Best,
Jonas Raoni

here is the result and it shows utf8mb3_general_ci with 166 rows.

Hmm, so let’s try to update the charset/collation, the utf8mb4 is basically an extension (supports more characters) of the utf8mb3.

The query below should generate a bunch of ALTER TABLE … commands, you can copy everything and execute (again, update YOUR_DATABASE_NAME by the name of your database) :grin:

SELECT CONCAT('ALTER TABLE `', table_name, '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;')
FROM information_schema.tables
WHERE table_schema = 'YOUR_DATABASE_NAME' AND table_collation != 'utf8mb4_0900_ai_ci';

Best,
Jonas Raoni

Hi @jonasraoni

Thanks for your excellent guidance every time, but I have a doubt, because of the huge database (20 GB) it may take a lot of time to execute, which might be risky.

Oh, I see… This isn’t a requirement, but whenever a user attempt to use an unsupported character, it will lead an error in the database.

I’m not completely sure this is causing the issue, but as you don’t have a helpful error and I can’t simulate it on my environment, then it will require a “poor man’s debugging” (removing any error protection and/or place checks on the code to understand where it’s stopping).

Best,
Jonas Raoni