SQL Problem when updating concrete version to the latest

Hello,

I am trying to update the concrete version from 9.1.3 to 9.2.7 but I am getting this error:

Doctrine \ DBAL \ Exception \ DriverException

An exception occurred while executing ‘ALTER TABLE OAuth2ClientScopes ADD CONSTRAINT FK_497E26F39ECFF1A8 FOREIGN KEY (clientIdentifier) REFERENCES OAuth2Client (identifier) ON DELETE CASCADE’: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint

Can anyone help me, please?

PHP version: 8.1.19
MySQL version: mysql Ver 14.14 Distrib 5.7.37

Hi @ felipemila,
Yes I recently did that same upgrade and had the same SQL error.
Since we were not doing anything with OAuth2, I did a fresh V9.2.7 install in my local dev environment and exported all the OAuth2 tables using phpadmin.
After restoring the V9.1.3 instance (following the SQL error), I then dropped all the OAuth2 tables in my V9.1.3 instance and imported the OAuth2 tables from the 9.2.7 fresh install. After that the upgrade to V9.2.7 worked.
We are still testing V9.2.7 in a hosted staging environment - so far no problems encountered.
Hope this assists. Regards,
Jeff.

1 Like

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;
1 Like

Hello, @hutman

I got a huge SQL output when I used: concrete/bin/concrete5 orm:schema-tool:update --dump-sql

Regarding the second step, can you explain a little bit more please.

Thank you!

Hello @jphoward,

I am not sure if we are doing some with OAuth2 but I will check with our DBAs if it is possible to do that.

Thank you!

Yes, you will get a big output, most of it is just keys and stuff. If you then go into your database with phpMyAdmin or Adminer you can use the SQL command function and run those without foreign key checks on and it should fix whatever missing migrations you have.