That code change might fix the error but I don't think that's what caused this. What I think has happened is that there's been a previous attempt to upgrade your site to Moodle 4.0 but this was rolled back to the previous version by restoring a MySQL/MariaDB backup. The problem with doing this is that any new tables added during the Moodle 4.0 upgrade do not get removed. So when you tried to upgrade again there's already a mdl_question_bank_entries with some data which is what's led to this error.
So alternatively you could drop (delete) the mdl_question_bank_entries from your Moodle 3.9 database before attempting the upgrade. Back up your database before making any changes like this.
(My opinion: I think Moodle shouldn't be doing a conditional create table for mdl_question_bank_entries so that an error occurs when it tries to create the table).