Database error update 2.4.8.2 to 3.0.2

I am trying to update my databse with the follow command:
php tools/upgrade.php upgrade

but I am getting a error:

(mysql): ALTER TABLE articles CHANGE COLUMN article_id submission_id INTEGER(20) NOT NULL AUTO_INCREMENT
-----



1025: Error on rename of ‘./ojs3/#sql-4e5_135a’ to ‘./ojs3/articles’ (errno: 150)
ADOConnection._Execute(ALTER TABLE articles CHANGE COLUMN article_id submission_id INTEGER(20) NOT NULL AUTO_INCRE$
ADOConnection.Execute(ALTER TABLE articles CHANGE COLUMN article_id submission_id INTEGER(20) NOT NULL AUTO_INCREMENT)% li$
Installer.executeSQL(ALTER TABLE articles CHANGE COLUMN article_id submission_id INTEGER(20) NOT NULL AUTO_INCREMENT)% line 435, $
Installer.executeSQL(Array[1])% line 435, file: /var/www/ojs3/lib/pkp/classes/install/Installer.inc.php
Installer.executeSQL(Array[27])% line 396, file: /var/www/ojs3/lib/pkp/classes/install/Installer.inc.php
ERROR: Upgrade failed: DB: Error on rename of ‘./ojs3/#sql-4e5_135a’ to ‘./ojs3/articles’ (errno: 150)

I am stuck in this part. Anyone could help me? Thanks.

Hi @xicaooo,

Have you manually configured foreign key relationships between tables/columns?

Regards,
Alec Smecher
Public Knowledge Project Team

Alec,

Yesterday I updated my ojs 2.4.8.1 to 2.4.8.2 and everything was fine. Today I tried to update to 3.0.2 and this error appeared.

I have never configured foreign key manually. It is so sad. I really wanna try the 3.0.2 version.

Thanks for your support.

Hi @xicaooo,

I see lots of references to this error in StackOverflow (e.g. this one). It appears to relate to renaming a table/column when it’s referred to using a foreign key constraint. OJS doesn’t use these, so I’m wondering if they exist and where they came from. What do you get for the following SQL query?

SHOW CREATE TABLE articles;

Regards,
Alec Smecher
Public Knowledge Project Team

articles | CREATE TABLE articles (
article_id bigint(20) NOT NULL AUTO_INCREMENT,
locale varchar(5) DEFAULT NULL,
user_id bigint(20) NOT NULL,
journal_id bigint(20) NOT NULL,
section_id bigint(20) DEFAULT NULL,
language varchar(10) DEFAULT ‘en’,
comments_to_ed text,
citations text,
date_submitted datetime DEFAULT NULL,
last_modified datetime DEFAULT NULL,
date_status_modified datetime DEFAULT NULL,
status tinyint(4) NOT NULL DEFAULT ‘1’,
submission_progress tinyint(4) NOT NULL DEFAULT ‘1’,
current_round tinyint(4) NOT NULL DEFAULT ‘1’,
submission_file_id bigint(20) DEFAULT NULL,
revised_file_id bigint(20) DEFAULT NULL,
review_file_id bigint(20) DEFAULT NULL,
editor_file_id bigint(20) DEFAULT NULL,
pages varchar(255) DEFAULT NULL,
fast_tracked tinyint(4) NOT NULL DEFAULT ‘0’,
hide_author tinyint(4) NOT NULL DEFAULT ‘0’,
comments_status tinyint(4) NOT NULL DEFAULT ‘0’,
documentocod int(11) DEFAULT NULL,
PRIMARY KEY (article_id),
KEY articles_user_id (user_id),
KEY articles_journal_id (journal_id),
KEY articles_section_id (section_id)
) ENGINE=InnoDB AUTO_INCREMENT=5011 DEFAULT CHARSET=utf8 |

Is the problem the ENGINE=InnoDB?

I used the command: SHOW ENGINE INNODB STATUS

and then i discovered which table was problematic. Then I used a command to drop the conflict foreign key:

ALTER TABLE table_name DROP FOREIGN KEY id_name_fk;

after that this error disappeared but now I am getting:

(mysql): DELETE FROM metrics WHERE load_id = ‘3.0.0-upgrade-timedViews’ 1146: Table ‘ojs3.metrics’ doesn’t exist

                                      ADOConnection._Execute(DELETE FROM metrics WHERE load_id = '3.0.0-upgrade-timedViews') % line 1032, file: adodb.inc.php
                                   ADOConnection.Execute(DELETE FROM metrics WHERE load_id = ?, Array[1]) % line  223, file: DAO.inc.php
                                DAO.update(DELETE FROM metrics WHERE load_id = ?, 3.0.0-upgrade-timedViews) % line  248, file: PKPMetricsDAO.inc.php
                             PKPMetricsDAO.purgeLoadBatch(3.0.0-upgrade-timedViews) % line  519, file: Upgrade.inc.php
                          Upgrade.migrateTimedViewsUsageStatistics(Object:Upgrade, Array[2]) % line    0, file: 

DB Error: Table ‘ojs3.metrics’ doesn’t exist

thanks for you support. I appreciated that.

I give it up. Now this error

Fatal error: require_once(): Failed opening required ‘/var/www/ojs3/plugins/generic/usageStats/GeoLocationTool.inc.php’ (include_path=’.:/var/www/ojs3/classes:/var/www/ojs3/pages:/var/www/ojs3/lib/pkp:/var/www/ojs3/lib/pkp/classes:/var/www/ojs3/lib/pkp/pages:/var/www/ojs3/lib/pkp/lib/adodb:/var/www/ojs3/lib/pkp/lib/phputf8:/var/www/ojs3/lib/pkp/lib/pqp/classes:/var/www/ojs3/lib/pkp/lib/smarty:.:/usr/share/php:/usr/share/pear’) in /var/www/ojs3/lib/pkp/includes/functions.inc.php on line 25

Hi @xicaooo,

Did you potentially mix your OJS 3.0.2 codebase in with your OJS 2.4.8-2 codebase? I suspect some old code is still present.

Regards,
Alec Smecher
Public Knowledge Project Team

I used this two patch and it fixed my problem.

https://github.com/bozana/ojs/commit/fc73c76729c724d90d6afa4a40e51d57520484a2

Hi @xicaooo,

Can you check those commit links? Neither of those works for me.

Regards,
Alec Smecher
Public Knowledge Project Team

Sorry, I changed it.

Hi @xicaooo,

Great – thanks for confirming!

Regards,
Alec Smecher
Public Knowledge Project Team

Hello everyone.

We have a OJS installation in version 2.4.8.2 but we started in 2.3.3 a few years ago and we keep it up to date.
Recently I tried performing the process of upgrading from OJS 2.4.8.2 to version 3.0.2
The first problem I encountered was this:

ERROR: Upgrade failed: DB: Duplicate entry '3358-3-1' for key 'review_rounds_submission_id_stage_id_round_pkey'

I put the configuration in debug mode for database and saw that the last commands are:

(mysql): UPDATE submissions SET stage_id=4 WHERE submission_id IN (SELECT e1.submission_id FROM edit_decisions e1 LEFT JOIN edit_decisions e2 ON (e2.edit_decision_id > e1.edit_decision_id AND e2.submission_id = e1.submission_id) WHERE e2.edit_decision_id IS NULL AND e1.decision = 1) 
   
-----<hr>
-----<hr>
(mysql): UPDATE review_rounds SET stage_id=3 

Is this latest UPDATE without the WHERE clause really right?
Searching here on the forum I found the response of someone who recommended running this in the database:

CREATE TABLE review_rounds_old SELECT * FROM review_rounds;
DELETE FROM review_rounds WHERE review_round_id NOT IN (SELECT MIN(review_round_id) FROM review_rounds_old GROUP BY submission_id, round);
DROP TABLE review_rounds_old;

I ran the above commands and running the update again and the duplicate entry error did not occur anymore. But another error occurred:

ERROR: Upgrade failed: DB: Duplicate entry 'defaultthemeplugin-0-enabled' for key 'plugin_settings_pkey'
And to pass from this point I had to comment the following lines in the dbscripts/xml/upgrade /3.0.0_update.xml file:

   <sql><!-- Make the default theme plugin active for all journals and the site. -->
            <query>INSERT INTO plugin_settings (plugin_name, setting_name, setting_value, setting_type, context_id) VALUES ('defaultthemeplugin', 'enabled', '1', 'bool', 0)</query>
            <query>INSERT INTO plugin_settings (plugin_name, setting_name, setting_value, setting_type, context_id) SELECT 'defaultthemeplugin', 'enabled', '1', 'bool', journal_id FROM journals</query>
            <query>INSERT INTO site_settings (setting_name, setting_value, setting_type) VALUES ('themePluginPath', 'default', 'string')</query>
            <query>INSERT INTO journal_settings (setting_name, setting_value, setting_type, journal_id) SELECT 'themePluginPath', 'default', 'string', journal_id FROM journals</query>
   </sql>

Then I started to run the update command and again another error:

<H1> DB Error: Data too long for column 'label' at row 1 </ h1> ojs2: DB Error: Data too long for column 'label' at row 1

I saw that this problem is related to the table submission_galleys that is created label column with size 255 on file dbscripts/xml/ojs_schema.xml
I did some searches in our base and in our ojs and saw that this table is filled by the form
GALLEY → EDIT A LAYOUT GALLEY that has field ‘label’ but the query also uses the form EDIT A SUPPLEMENTARY FILE → SUPPLEMENTARY FILE METADATA that instead of ‘label’ has field ‘title’.
So to get past this problem I had to change the schema so that the label field was 512, so it could hold the biggest title of my base.

By doing these interventions the upgrade process ends but I can not access the administration menu, the options do not appear, and there are problems with the theme used.

So anyone else had to deal with this problem?
Can such database interventions be a problem for future updates?

Thanks in advance!!!
Gessy

Hi @Gessy_Junior,

Each time you re-try an upgrade, make sure you’re dropping your database entirely and restoring it and the files directory from backup, then performing any additional queries, then retrying the upgrade. I wonder if you’re attempting to pick up a failed upgrade from the point at which it failed.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher

I have refactored the whole process from the beginning and every time I encountered a problem I returned a dump of the database and files. I encountered the same problems and just got through with the modifications I showed earlier.

Thank you
Gessy

Hi @Gessy_Junior,

When you say that the upgrade process ends (after the interventions you mentioned), do you get a confirmation of a successful upgrade, or does the upgrade appear to stop? If you’re using e.g. the web-based upgrade process, it’s possible that it’s hitting a 30-second timeout (if your server is configured that way). If you don’t get a confirmation, it’s worth also checking your PHP error log to see if something relevant is there.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher

The process ends showing release notes and new features. I did a fresh install with ojs 2.4.8.2 and upgrade to 3.0.2 with no journals and indeed no modifications are needed. Our database has some data that causes those problems but the data was inputted from OJS in older versions…

I using CLI method with command php tools/upgrade.php upgrade

Thank you so much
Gessy

Hi @Gessy_Junior,

Gotcha. One thing to check is the file permissions on the cache/ subdirectory – the requirements are described in docs/README. You should be able to delete all .php/.css files from cache/ and see them getting re-generated automatically when you work with the OJS web interface.

Can you describe the remaining problems in more detail?

Regards,
Alec Smecher
Public Knowledge Project Team

Hello @asmecher

Well … I detailed as much as I could when I wrote the message at Database error update 2.4.8.2 to 3.0.2 - #14 by Gessy_Junior

I think it’s worth adding that in the first issue about duplicate entry, looking in the forum I saw this post Upgrade to 3.0.0: pkey violation on review_rounds · Issue #1921 · pkp/pkp-lib · GitHub and I used it in my database and The upgrade process then passed without this error. I changed the configuration in config.inc.php to debug mode for database and I was able to see the SQLs that the script executes and so I posted them previously at the point where the problem occurs.

The errors referring to the duplicate entries again in the plugin_settings table, but only the queries below return error

<Query> INSERT INTO plugin_settings (plugin_name, setting_name, setting_value, setting_type, context_id) VALUES ('defaultthemeplugin', 'enabled', '1', 'bool', 0)
<Query> INSERT INTO site_settings (setting_name, setting_value, setting_type) VALUES ('themePluginPath', 'default', 'string') </ query>

Once again, thank you very much for everything.
Gessy

Hi @Gessy_Junior,

Those queries tell OJS 3.x to use the “default” theme plugin. That plugin didn’t exist in OJS 2.x, so those rows shouldn’t have existed before. If you’re getting a duplicate row error on these, then it suggests to me that this part of the upgrade has been run previously somehow.

Can you check your OJS 2.x backup to see whether those rows exist? For example:

select * from plugin_settings where plugin_name='defaultthemeplugin';

Regards,
Alec Smecher
Public Knowledge Project Team