Serious issue with Database upgrade (failed from 3.2.1.3 to 3.3.0.2)

Good morning,
today I updated ad usual the software to the latest one available.
When it has been the time of upgrading the db,
I receive this fatal error:

php tools/upgrade.php upgrade

[pre-install]
[load: upgrade.xml]
[version: 3.3.0.2]

[code: Installer Installer::checkPhpVersion]

[code: Installer Installer::installDefaultNavigationMenus]
WARNING: The NavigationMenu (ContextId: 1, Title: User Navigation Menu, Area: user) will be skipped because the specified area has already a NavigationMenu attached.
WARNING: The NavigationMenu (ContextId: 1, Title: Primary Navigation Menu, Area: primary) will be skipped because the specified area has already a NavigationMenu attached.
WARNING: The NavigationMenu (ContextId: 0, Title: User Navigation Menu, Area: user) will be skipped because the specified area has already a NavigationMenu attached.

[code: Installer Installer::migrateStaticPagesToNavigationMenuItems]
[migration: PKPv3_3_0UpgradeMigration]
ERROR: Upgrade failed: DB: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table review_round_files add constraint review_round_files_submission_file_id_foreign foreign key (submission_file_id) references submission_files (submission_file_id))

Any ideas?
thank you in advance for your help.

–Carlo

3 Likes

Hi @Carlo_Manuali,

The error means that in the database, review_round_files table during upgrade has values in submission_file_id that don’t correspond to the values in submission_files table, submission_file_id column.

This should be fixed as part of this issue: Foreign key constraint error during upgrade in review_round_files.submission_file_id · Issue #6337 · pkp/pkp-lib · GitHub, so I’m not sure why the error occurs in your case. Can you follow the debugging procedure there and look at the partially updated database for those values:

SELECT submission_file_id FROM review_round_files LEFT JOIN submission_files USING (submission_file_id) WHERE submission_files.submission_file_id IS NULL

Something similar here while installing 3.3.0:

Errors occurred during installation
A database error has occurred: SQLSTATE[HY000] [1049] Unknown database ‘ojs33’ (SQL: create table announcement_types (type_id bigint not null auto_increment primary key, assoc_type smallint not null, assoc_id bigint not null) default character set utf8 collate ‘utf8_general_ci’)

Hi @Franklinx,

It sounds like you’re trying to install without creating a database first.

Regards,
Alec Smecher
Public Knowledge Project Team

As we have try to upgrade the OJS from 3.2.1.3 to 3.3.0.2 this error caused by the different storage engine between that related table.

This reference explained more about some case regarding this issue :

Okay. I tried that and it works. Thanks. Much appreciated. I tried to understand why I made this obvious mistake. What I see is that PKP has removed from the webinstall page the standard option to (automatically) create a database. That’s fine. But perhaps you could then add a note to the installation instructions that a database should be created first.

  1. Extract the OJS archive
  2. Make the following files and directories (and their contents) writeable
  3. Create a directory to store uploaded files
  4. Create a SQL database
  5. Open a web browser and follow the on-screen installation instructions.

Dear Vitaliy, sorry for my late answer but I missed notifications.
That is not my case, in fact the SQL command above return me an empty set.
I also tried to do manually:

I don’t know if the fact to have used only 1 parenthesis at the end could guide to something, because first of all I tried to copy and paste from the original error in which it seems to use double. In this case I received a syntax error when running from console.

Again, I verified that the two tables are using a different engine.
If I move the ‘submission_files’ table to InnoDB with:

that problem seems to be surpassed.
Now I receive back this warning and error:

Any help?

Who can help with the upgrade issue?
[Wed Feb 03 08:49:26.024616 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: PHP Fatal error: Uncaught Error: Call to a member function getConnection() on null in /var/www/www-root/data/www/sworldjournal.com/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Capsule/Manager.php:74
[Wed Feb 03 08:49:26.024656 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: Stack trace:
[Wed Feb 03 08:49:26.024661 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: #0 /var/www/www-root/data/www/sworldjournal.com/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Capsule/Manager.php(200): Illuminate\Database\Capsule\Manager::connection()
[Wed Feb 03 08:49:26.024664 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: #1 /var/www/www-root/data/www/sworldjournal.com/lib/pkp/classes/db/DAO.inc.php(65): Illuminate\Database\Capsule\Manager::__callStatic(‘raw’, Array)
[Wed Feb 03 08:49:26.024667 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: #2 /var/www/www-root/data/www/sworldjournal.com/lib/pkp/classes/context/ContextDAO.inc.php(63): DAO->retrieve(‘SELECT * FROM j…’, Array)
[Wed Feb 03 08:49:26.024670 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: #3 /var/www/www-root/data/www/sworldjournal.com/lib/pkp/classes/core/PKPRouter.inc.php(252): ContextDAO->getByPath(‘en’)
[Wed Feb 03 08:49:26.024673 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: #4 /var/www/www-root/data/www/sworldjournal.com/lib/pkp/classes/core/PKPRequest.inc.php(760): PKPRouter->getContext(Object(Request), 1)
[Wed Feb 03 08:49:26.024676 2021] [fcgid:warn] [pid 23030] [client 144.76.3.131:52974] mod_fcgid: stderr: #5 /var/www/www-root/data/www/sworldjournal.com/classes/core/Request.inc.php(64): PK in /var/www/www-root/data/www/sworldjournal.com/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Capsule/Manager.php on line 74

Problems with the database server?

Server: MySQL (Localhost via UNIX socket)
Server type: MariaDB
Server version: 5.5.68-MariaDB - MariaDB Server
Protocol version: 10
Server encoding: UTF-8 Unicode (utf8)

This problem is documented at #6710 and there’s a suggested fix there.

This problem is being discussed at #6703 and an answer should be available there soon.

#6710 - version 3.0. And I’m upgrading from 3.2. by 3.3.

Just an error in the title. It’s dealing with a 3.3 issue.

please explain what to do

Finally I successfully upgraded to 3.3.0.2.

For those following this thread my solution has been:

  1. ALTER TABLE submission_files ENGINE = InnoDB;
    due to all the tables need to use the same engine for being linked by a foreign key;

  2. Apply this patch: pkp/pkp-lib#6710 Unserialize journal settings depending on a value data type by Vitaliy-1 · Pull Request #6715 · pkp/pkp-lib · GitHub

Both before running the update.

Thanks to all.

5 Likes

Can you explain Step 1? What file needs to be edited for that?

Can someone clarify what this means and where to make the edit:
ALTER TABLE submission_files ENGINE = InnoDB;

I can answer my own question.

  1. Go to phpMyAdmin (or MySQL workbench or whatever database manager you’re using)
  2. Open your OJS database
  3. Click and open the submission_files table. If you’re using phMyAdmin, all of your tables should be listed as soon as you open your OJS database, so scroll down and click submission_files.
  4. In the top menu, click Operations.
  5. In the middle of the page, you’ll see Table Options. Choose InnoDB in the drop down menu for Storage Engine and click the GO button beneath.

It might also help to do the following:

  1. go to the landing page for phpMyAdmin without any databases selected
  2. Click Variables in the top menu
  3. Search for engine in the search box
  4. Edit the default storage engine so its InnoDB and not MyISAM
  5. The Storage Engine entry will change to InnoDB as well, but you can edit that too.

I’m trying to upgrade to 3.3.0-3, which appears to have all the patches installed already.

Upgrade still fails on my wampserver. I’m not going to try this on my main web host till I can get it to work on my test server.

[08-Feb-2021 18:14:50 UTC] PHP Fatal error:  Uncaught Error: Call to a member function getConnection() on null in C:\wamp64\www\ojs\lib\pkp\lib\vendor\laravel\framework\src\Illuminate\Database\Capsule\Manager.php:74

Stack trace:
#0 C:\wamp64\www\ojs\lib\pkp\lib\vendor\laravel\framework\src\Illuminate\Database\Capsule\Manager.php(200): Illuminate\Database\Capsule\Manager::connection()
#1 C:\wamp64\www\ojs\lib\pkp\classes\db\DAO.inc.php(65): Illuminate\Database\Capsule\Manager::_callStatic(‘raw’, Array)
#2 C:\wamp64\www\ojs\lib\pkp\classes\plugins\PluginSettingsDAO.inc.php(106): DAO->retrieve('SELECT setting
…’, Array)
#3 C:\wamp64\www\ojs\lib\pkp\classes\plugins\PluginSettingsDAO.inc.php(86): PluginSettingsDAO->getPluginSettings(‘0’, ‘announcementfee…’)
#4 C:\wamp64\www\ojs\lib\pkp\classes\cache\GenericCache.inc.php(63): PluginSettingsDAO->_cacheMiss(Object(FileCache), ‘enabled’)
#5 C:\wamp64\www\ojs\lib\pkp\classes\plugins\PluginSettingsDAO.inc.php(57): GenericCache->get(‘enabled’)
#6 C:\wamp64\www\ojs\lib\pkp\classes\plugins\Plugin.inc.php(463): P in C:\wamp64\www\ojs\lib\pkp\lib\vendor\laravel\framework\src\Illuminate\Database\Capsule\Manager.php on line 74

I even downloaded the OJS database, changed all MyISAM text to InnoDB, uploaded that, and the same error is logged. So there’s more to the update fails than just altering one or all tables to InnoDB.

Okay, the last thing that needs to be done is go here:
ojs\lib\pkp\classes\install\form\UpgradeForm.inc.php

Add this to line 36:
Application::get()->initializeDatabaseConnection();

As asmecher pointed out in another thread: pkp/pkp-lib#6703 Fix web-based upgrade form by asmecher · Pull Request #6719 · pkp/pkp-lib · GitHub

Finally updated this site on wampserver. Not sure if switching every table to InnoDB is necessary. You’ll have to try just switching the submission_file table and then all of them if it isn’t enough.

1 Like

Hi @SilverBoot,

Thanks for continuing to document your progress – I hope it’s helpful to others!

Regarding your uncertainty:

Not sure if switching every table to InnoDB is necessary.

Previous to OJS 3.3, we didn’t formally declare any FOREIGN KEY relationships between database tables. We will be continuing to add formal declarations of these as part of issue #6093 – it helps detect database inconsistencies and will allow us to tighten up our code over the long term, plus it will allow us to produce database diagrams and self-documentation using tools like the excellent SchemaSpy. So over the next several releases we’ll be adding more of these FOREIGN KEY constraints, where 3.3 only added them to one or two tables.

However, we’ll be looking into the reason that you’re seeing these Cannot add foreign key constraint messages, and will try to figure out a way that won’t require the manual change of storage engines. Watch for some news on that.

Regards,
Alec Smecher
Public Knowledge Project Team

2 Likes

Have the same PHP log error
PHP Fatal error: Uncaught Error: Call to a member function getConnection() on null in … public_html/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Capsule/Manager.php on line 74
I tried every step you made
Any Ideas?
I’m tring to upgrade from 3.2.1.3 to 3.3.0.3

1 Like