Hello!
I'm trying to update my 3.3.1 moodle to 3.5.13 (and eventually to 3.9+). Unfortunately, I'm receiving the following error:

How can I fix this? Thanks so much for your help!
Yes, case is important and LHHS_course_sections is not the same as lhhs_course_sections. It looks like this is tied to directory names so if you were moving from Microsoft Windows to Linux the case sensitivity could change.
Presumably $CFG->prefix is 'lhhs_'. What are the other table names, e.g. do you have lhhs_course or LHHS_course, lhhs_user or LHHS_user, etc.
Thank you for the reply. They are all LHHS_. Is there a way I can fix this?
If they're all LHHS_ I think you could just change $CFG->prefix to 'LHHS_' in config.php (which is in the Moodle source code folder).
Hopefully when you refresh the page and the upgrade will work.
That StackOverflow link in my first reply suggests lower_case_table_names could be non-0. Can you run the SQL query:
SHOW GLOBAL VARIABLES LIKE 'lower_case_table_names';
I'd expect this to be 0 but the behaviour you describe sounds like it's set to 2. From the documentation this setting has operating system-specific settings. So the next question is what OS is the database hosted on and what database type (MySQL, MariaDB) and version is in use?
Presumably if this setting is a problem now the database would be being moved from one OS to another – is this the case and if so from what to what?
A solution might be to get a list of all table names in a text editor and prepare lots of RENAME TABLE statements to change each table's name. Take a back up of the database before making any changes like this.
It looks like I was wrong about lower_case_table_names and it appears that Moodle doesn't actually work with an upper- (or mixed-) case $CFG->prefix which I find surprising. MDL-43189 seems to confirm this but I can't tell why it's the case. Presumably this must have been possible at some point.
A script that could easily do them all at once? Are you comfortable working at the command line and do you have shell access to MySQL, i.e. can you run the mysql command to see the database? The following should work (I tested it as well as I could) but be careful:
1. Back up the database.
2. Change $CFG->prefix to 'lhhs' in config.php.
3. Run the command below:
mysql -u root -p aslwithr_lhhs -BNe 'SHOW TABLES' > tables
The file tables should contain a list of the tables in the aslwithr_lhhs database (LHHS_analytics_indicator_calc, LHHS_analytics_models, etc.), one per line.
4. Run the command:
sed -e '/^\LHHS_/!d' -e 's/^\(LHHS_\)\(.\+\)/RENAME TABLE \1\2 TO lhhs_\2;/' tables > rename.sql
This reads from file tables to generate the file rename.sql containing the RENAME TABLE statements to change each table from LHHS_table_name to lhhs_table_name. Check this file looks correct.
5. Run the command:
mysql -u root -p aslwithr_lhhs < rename.sql
This should perform the renames. Check the table names are now all lhhs_table_name.
For steps 3. and 5. if you don't have root access to MySQL hopefully you do have an account with suitable privileges.
This assumes that only Moodle tables are named LHHS_.
Now hopefully the upgrade can proceed.
If you run SHOW CREATE TABLE for lhhs_quiz_slots is the prefix for the KEY objects is the prefix upper case or lower case?
SHOW CREATE TABLE lhhs_quiz_slots;
| lhhs_quiz_slots | CREATE TABLE `lhhs_quiz_slots` (
⋮
KEY `lhhs_quizslot_qui_ix` (`quizid`),
KEY `lhhs_quizslot_que_ix` (`questionid`)
I'm going to guess these are upper case in which case renaming the tables wasn't enough.
As Ken said MySQL backups are text files which can be edited. So we may find it easiest to edit a copy of the backup file, delete and re-create the database, then restore the edited file.
If you have a database backup taken immediately before attempting the upgrade (always do this!) then it's best to work from that, it's a better starting position than proceeding with an upgrade that's failed twice.
Steps:
1. Make a copy of the database backup file leaving the original untouched. Let's call this copy backup2.sql.
2. Run the following command to read this copy renaming everything tables, indexes, constraints:
sed -e 's/`mdl_/`lhhs_/' backup2.sql > rename_all.sql
The edited backup file is rename_all.sql.
3. Delete and recreate the Moodle database. Assuming you have sufficient permissions and your MySQL supports the recommended character encoding this might be:
DROP DATABASE aslwithr_lhhs;
CREATE DATABASE aslwithr_lhhs DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
But this might vary for you. If you don't have the necessary permissions you might need to drop all tables individually. If so we could prepare a script similar to the RENAME TABLE one.
Obviously be very careful! I'm assuming that database aslwithr_lhhs only contains this Moodle site's tables.
4. Restore the database from the edited backup file:
mysql -u root -p aslwithr_lhhs < rename_all.sql
Hopefully now there's a database with lower case table prefixes, and all the constraints and indexes also have the same prefix. You could re-run SHOW CREATE TABLE lhhs_quiz_slots to verify this before attempting the upgrade again.
1. My command is wrong, apologies. I'm changing the commands I'm testing on my system to match your system and I missed this. It should be:
sed -e 's/`LHHS_/`lhhs_/' backup2.sql > rename_all.sql
2. So what I'm suggesting is using the above command to modify the text-based database backup so that both tables and indexes have the lhhs_ prefix. The challenge is that unlike with tables which you can rename you can't do this with indexes (you can but with a later MySQL version). The approach carries risk and you're right to be wary. It could be that
there's something in the way that the server is set up that prevents
the steps from working, something I've not taken into account, or an
error (as above).
You're correct about needing to uncompress the database backup if that's being compressed. On the server you can use gzip -d for this, e.g. gzip -d backup.sql.gz would change the file to the uncompressed backup.sql.
The sed command is just doing a search and replace so you could do that in a text editor if it can handle the file (it might be too large). But note that the backtick (`) is part of the search and replace to try to more accurately match object names.
If the character set is currently utf8 then continue to use that (with corresponding collation utf8_unicode_ci). utf8mb4 is the recommended setting but switching to that is a job in itself so can be deferred for now!
Here's an alternative which changes the indexes only. This assumes that you've got the uncompressed database backup on the server and the server has the stndard command awk installed. You'll need the attached file on the server too.
1. Put the uncompressed database backup, e.g. backup.sql, and the attached file, rename_indexes.awk on the server.
2. At the shell run the command:
awk -f rename_indexes.awk backup.sql > rename_indexes.sql
This should create file rename_indexes.sql containing an ALTER TABLE … DROP INDEX/ALTER TABLE … ADD INDEX for every index, changing the case of the prefix.
3. Run the following command to run the above statements.
mysql -u root -p aslwithr_lhhs < rename_indexes.sql
Caveat: recreating all indexes could be time consuming on all but the smallest Moodle sites. It may also cause high server load while it's running.
Turn on debugging ... all the way to developer.
Also check web service error logs.
Have you double checked ownerships/permissions of new code files/directories?
What is value/variable for cfg wwwroot? (url) ... does that match how web server will respond to any request?
'SoS', Ken
Something is breaking the JavaScript for the page, there's an error in the browser console. Can you tell us what additional plugins are installed (from Site administration ▶ Plugins ▶ Plugins overview click Additional plugins)? Are they all compatible with Moodle 3.9 and are the versions up-to-date? It's possible there's a plugin that's not compatible causing a conflict.
The other place to check is Site administration ▶ Appearance ▶ Additional HTML to see if any scripts have been added but I don't think that's the case.
Are you using Softaculous to perform the upgrade? I think this isn't removing the old Moodle files beforehand. This is why you're seeing additional plugins listed, they're old core plugins that have been retired. Removing old source code files is an important step in upgrading: "Do NOT copy new files over the old files".
Assuming the above is correct you'll need to get whoever is providing services with Softaculous to resolve this.
Or you can follow the instructions for upgrading, and extract the source code to a clean directory.
The problem with the links not working could probably be fixed by:
This should fix the navigation problems but I don't recommend it for a production site as you would still have the retired plugins and who-knows-what other files left behind.
I'll point you in the direction of this reply.
This row is from one of the plugins removed between 3.3 and 3.9. The row should get removed as part of the upgrade process. I've confirmed that it does using a test site but clearly you're not the only person ever to encounter this.
Congrats! Now let's look to the future! What are some of the take away's from this 'hardest' upgrade?
'SoS', Ken
Key ... 'shared' ... means that when changes to DB server needed you don't have access rights (privs) to do them - shared DB server as well. Because you are on a shared system provider won't make changes cause that affects all customers on that same shared system/db.
Kinda curious about what's in your DB. Can you download an sql dump of DB? That's an ascii file (text) and you should be able to open that with a true text editor (don't use Office Suites).
One should be able to find lines for 'CREATE TABLE ... etc.
'SoS', Ken
+1 to what Leon said ... but a question ... maybe for both of you ... and for my education ...
In the error trace ..
2nd box Debug info line:
aslwtthr_lhhs.lhhs_course_sections
prefix is lhhs_ - defined in config.php
What is aslwtthr_lhhs - that a database name?
'SoS', Ken