Cannot edit existing emails after upgrade from Mautic 3 to 4.4.5

Your software
My PHP version is : PHP 7.4.33
My MySQL/MariaDB version is (delete as applicable): 5.7.39-42

Updating/Installing Errors
I am (delete as applicable): Updating
Upgrading/installing via (delete as applicable) : Command Line

These errors are showing in the installer :

These errors are showing in the Mautic log :
[2022-12-28 19:55:03] console.CRITICAL: Error thrown while running command “doctrine:migrations:migrate --quiet --no-interaction”. Message: “An exception occurred while executing ‘ALTER TABLE oauth2_clients ADD CONSTRAINT FK_CLIENT_ROLE FOREIGN KEY (role_id) REFERENCES roles (id)’: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint” {“exception”:“[object] (Doctrine\DBAL\Exception\DriverException(code: 0): An exception occurred while executing ‘ALTER TABLE oauth2_clients ADD CONSTRAINT FK_CLIENT_ROLE FOREIGN KEY (role_id) REFERENCES roles (id)’:\n\nSQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint at /home/customer/www/msg.saudeplena.org/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:128, Doctrine\DBAL\Driver\PDO\Exception(code: HY000): SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint at /home/customer/www/msg.saudeplena.org/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: HY000): SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint at /home/customer/www/msg.saudeplena.org/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:141)”,“command”:“doctrine:migrations:migrate --quiet --no-interaction”,“message”:“An exception occurred while executing ‘ALTER TABLE oauth2_clients ADD CONSTRAINT FK_CLIENT_ROLE FOREIGN KEY (role_id) REFERENCES roles (id)’:\n\nSQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint”} {“hostname”:“gfram1.siteground.biz”,“pid”:4505}

Your problem
My problem is :
I was upgrading on the command line, and the first try to finish it gave an error, asking to check details in the log file, which is shown above. The second try it passed.

Just when opening existing emails, I cannot edit them. The same happens if I clone existing emails. On my other instances I could resolve it by putting on the beginning of each email. This time it did not help to resolve the problem. The button for opening the GrapeJS editor is greyed out for most of the existing emails. Seems I can create new emails without any problems.

Hi, the template files change between M3 and M4.
You need to define grapesjs builder as an array the template config.

Here is the reference what needs to be changed for each template you use:

Actually I have no problem with creating new emails using the templates, I have a problem with opening emails I have been writing before. Found out now that he changed them all to the code mode template, and I have just the HTML under advanced settings. Just under Mautic 3 they have been opening fine with GapeJS. What had happened to my emails, and how can I revert that?