Upgrade 3.6.1+ to 3.10.3+ -> Default exception handler: Table "badge_alignment" already exists Debug: can not rename table

Upgrade 3.6.1+ to 3.10.3+ -> Default exception handler: Table "badge_alignment" already exists Debug: can not rename table

by Alter Ego -
Number of replies: 3

I made 2 attempts to upgrade from 3.6.1 to 3.10.3.  This first attempt was botched, resulting in either the error regarding code/database mismatch or an "error/generalexceptionmessage".

(system config at bottom of posting)

I fell back to 3.6.3 (renamed moodle.backup back to moodle, and ran the mysqldump sql file against the DB to restore it.

The system came back up and appeared to worked normally (I was able to poke around in moodle and ran a few courses)

I have now restarted the process:

1) placed moodle into maintenance mode

2) downloaded 3.10 latest

3) rename moodle to moodle.backup and extracted the tgz file

4) copied the config.php, changed ownership and permissions of moodle/*

5) Ran the upgrade script:

# php admin/cli/upgrade.php
== Upgrading Moodle database from version 3.6.1+ (Build: 20181220) (2019032200.02) to 3.10.3+ (Build: 20210330) (2020110903.01) ==

Your Moodle files have been changed, and you are about to automatically
upgrade your server to this version:

3.10.3+ (BUILD: 20210330) (2020110903.01)

Once you do this you can not go back again. Please note that this process
can take a long time.

Are you sure you want to upgrade this server to this version?

type y (means yes) or n (means no)
: y
-->System
Default exception handler: Table "badge_alignment" already exists Debug: can not rename table
Error code: ddltablealreadyexists
* line 514 of /lib/ddl/database_manager.php: ddl_exception thrown
* line 1189 of /lib/db/upgrade.php: call to database_manager->rename_table()
* line 1862 of /lib/upgradelib.php: call to xmldb_main_upgrade()
* line 187 of /admin/cli/upgrade.php: call to upgrade_core()

!!! Table "badge_alignment" already exists !!!
!! can not rename table
Error code: ddltablealreadyexists !!
!! Stack trace: * line 514 of /lib/ddl/database_manager.php: ddl_exception thrown
* line 1189 of /lib/db/upgrade.php: call to database_manager->rename_table()
* line 1862 of /lib/upgradelib.php: call to xmldb_main_upgrade()
* line 187 of /admin/cli/upgrade.php: call to upgrade_core()
 !!

-----------------------------------------------------------------

I attempted to rename the table (as recommended in another post):

MariaDB [moodle]> rename table badge_alignment to badge_alignment_old;
ERROR 1146 (42S02): Table 'moodle.badge_alignment' doesn't exist
--------------------------------------------------------------------

SYSTEM CONFIGURATION:

Linux: Ubuntu 20.04.2 LTS

php: PHP 7.4.16 (cli) (built: Mar  5 2021 07:54:38) ( NTS )

(there is also php7.0 available to moodle 3.6.3: PHP 7.0.33-47+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Feb 23 2021 15:04:06) ( NTS ) )

DB: Server version: 10.3.27-MariaDB-1:10.3.27+maria~bionic-log mariadb.org binary distribution

-----------------------------------------------------------------------

How can I resolve this issue?  Have I missed a step in the fall-back procedure?  Is there something I missed in the upgrade?

Average of ratings: -
In reply to Alter Ego

Re: Upgrade 3.6.1+ to 3.10.3+ -> Default exception handler: Table "badge_alignment" already exists Debug: can not rename table

by Matt T -
Please have a look at Leon's post here, I think it will address your issue. 

https://moodle.org/mod/forum/discuss.php?d=412848#p1664870

Unfortunately I suspect your rollback was imperfect. You really needed to drop the database and recreate it from the dump.

Now, it's likely that the 'table doesn't exist' error you got on MySQL CLI is because Moodle prefixes database tables with mdl_ by default - so you would need to prefix it with that. But - I strongly suggest leaving manual database tinkering to an absolute last resort option. 

Please try what is suggested in Leon's post first. It is a cleaner solution. You may also want to take a full backup of your site as is - and restore it as a duplicate site, so you can later copy across any user content added since your first dump was taken. 

If you continue as is - or manually rename that table as you were trying to do - your database will likely be left in an unpredictable and unstable state. 
In reply to Matt T

Re: Upgrade 3.6.1+ to 3.10.3+ -> Default exception handler: Table "badge_alignment" already exists Debug: can not rename table

by Alter Ego -
Thank-you for the quick response.

I dropped the database, and recreated it from the backup.

I ran the upgrade.php, it did not report any errors.

I ran the "php admin/cli/maintenance.php --disable", it did not report any errors

I tried to browse to the site. However, I am getting the following (I added the debug lines to the config.php):

Error
error/generalexceptionmessage
Debug info:
Error code: generalexceptionmessage
$a contents: syntax error, unexpected '='
Stack trace:

line 6675 of /lib/moodlelib.php: ParseError thrown
line 34 of /config.php: call to require_once()
line 30 of /index.php: call to require_once()

Any additional direction would be appreciated.
In reply to Alter Ego

Re: Upgrade 3.6.1+ to 3.10.3+ -> Default exception handler: Table "badge_alignment" already exists Debug: can not rename table

by Alter Ego -
In referring to this post:
https://moodle.org/mod/forum/discuss.php?d=407222

I have determined that the version of php that apache was using was the "old" version (7.0)

Create /var/www/html/phpinfo.php with the following:
<?php
  phpinfo();
?>

Browse to the server: www.myserver.com/phpinfo.php
The browser showed php v7.0 being used.

Ran the following commands to disable the old version and enable the new version:
# a2dismod php7.0
# a2enmod php7.4
# systemctl restart apache2

Refreshing the browser, the correct (7.4) version of php was displayed.

Deleted /var/www/html/phpinfo.php

My Moodle site is up again.