Refresh Database Entities Throws Error

I have converted a site with an Elemental theme from 8.5.15 to 9.2.7. Everything runs perfectly fine under php 8.2.15 exept:

When I try to refresh Database Entities, the System barks with this error:

Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException thrown with message "An exception occurred while executing ‘ALTER TABLE AttributeSets ADD CONSTRAINT FK_FCA02D5FCE45CBB0 FOREIGN KEY (pkgID) REFERENCES Packages (pkgID)’:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (ethzch_mbh_db02.#sql-alter-250db-8801748, CONSTRAINT FK_FCA02D5FCE45CBB0 FOREIGN KEY (pkgID) REFERENCES Packages (pkgID))»

I tried solutions posted on that very topic without success.

How can I fix this?

Appreciate any help to know more about it.

Thanks.

This happens sometimes when a migration is missed in the upgrade process. If you run this code from the CLI you can get the missing queries

concrete/bin/concrete5 orm:schema-tool:update --dump-sql

Then you can run those using phpMyAdmin or adminer like this

SET FOREIGN_KEY_CHECKS=0;
//output from the CLI
SET FOREIGN_KEY_CHECKS=1;

Thank you @hutman for the hint. I have no access to CLI, so I asked the hosting company to perform that check. But with no success, - I was told that the client probably installed a app and removed it. That must have been prior to v.8.

I wonder if the site runs without the possibility to refresh the database?

That makes sense as the error goes, you could use phpMyAdmin or something similar to try to remove the pkgID from the offending row in AttributeSets

In the meantime they found the problem but are unable to fix it. There was an old package “d3_random_image” which was deleted a long time ago. We fixed the package to run with php 8+, but probably new ID is different and problem persist.
We’re still trying…
Thanks again and bon weekend.