Database errors while upgrading

Created on 27 February 2023, over 1 year ago
Updated 14 March 2023, over 1 year ago

Problem/Motivation

While upgrading from 7.x-4.0-rc11 to 7.x-5.8 first there were some dependencies like views and rules that were not met. I installed these dependencies and ran update.php

Steps to reproduce

1. Upgrade from 7.x-4.0-rc11 to 7.x-5.8
2. Install views, rules
3. Run update.php
4. Get the error:

Failed: DatabaseSchemaObjectExistsException: Cannot add unique key result_answer to table quiz_node_results_answers: unique key already exists. in DatabaseSchema_mysql->addUniqueKey() (line 430 of /home/customer/www/test.domain.com/public_html/includes/database/mysql/schema.inc).
quiz_question module
Update #7500
Failed: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1171 All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: ALTER TABLE {quiz_question_properties} ADD `qqp_id` INT NULL auto_increment DEFAULT NULL, ADD PRIMARY KEY (`qqp_id`); Array ( ) in db_add_field() (line 2977 of /home/customer/www/test.domain.com/public_html/includes/database/database.inc).
long_answer module
Update #7500
Failed: DatabaseSchemaObjectExistsException: Cannot add field quiz_long_answer_user_answers.result_answer_id: field already exists. in DatabaseSchema_mysql->addField() (line 341 of /home/customer/www/test.domain.com/public_html/includes/database/mysql/schema.inc).
truefalse module
Update #7500
Failed: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1171 All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: ALTER TABLE {quiz_truefalse_user_answers} ADD `answer_id` INT NULL auto_increment DEFAULT NULL, ADD PRIMARY KEY (`answer_id`); Array ( ) in db_add_field() (line 2977 of /home/customer/www/test.domain.com/public_html/includes/database/database.inc).
short_answer module
Update #7500
Failed: DatabaseSchemaObjectExistsException: Cannot add field quiz_short_answer_user_answers.result_answer_id: field already exists. in DatabaseSchema_mysql->addField() (line 341 of /home/customer/www/test.domain.com/public_html/includes/database/mysql/schema.inc).
multichoice module
Update #7502
Failed: DatabaseSchemaObjectExistsException: Cannot add field quiz_multichoice_user_answers.result_answer_id: field already exists. in DatabaseSchema_mysql->addField() (line 341 of /home/customer/www/test.domain.com/public_html/includes/database/mysql/schema.inc).
matching module
Update #7501
Failed: DatabaseSchemaObjectExistsException: Cannot add field quiz_matching_user_answers.result_answer_id: field already exists. in DatabaseSchema_mysql->addField() (line 341 of /home/customer/www/test.domain.com/public_html/includes/database/mysql/schema.inc).

While acessing the pages that contain my quizes I get the error

Error message
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'base.qnp_id' in 'field list': SELECT base.qnp_id AS qnp_id, base.vid AS vid, base.nid AS nid, base.uid AS uid, base.number_of_random_questions AS number_of_random_questions, base.max_score_for_random AS max_score_for_random, base.pass_rate AS pass_rate, base.summary_pass AS summary_pass, base.summary_pass_format AS summary_pass_format, base.summary_default AS summary_default, base.summary_default_format AS summary_default_format, base.randomization AS randomization, base.backwards_navigation AS backwards_navigation, base.keep_results AS keep_results, base.repeat_until_correct AS repeat_until_correct, base.quiz_open AS quiz_open, base.quiz_close AS quiz_close, base.takes AS takes, base.show_attempt_stats AS show_attempt_stats, base.time_limit AS time_limit, base.quiz_always AS quiz_always, base.time_left AS time_left, base.max_score AS max_score, base.allow_skipping AS allow_skipping, base.allow_resume AS allow_resume, base.allow_jumping AS allow_jumping, base.allow_change AS allow_change, base.allow_change_blank AS allow_change_blank, base.build_on_last AS build_on_last, base.show_passed AS show_passed, base.mark_doubtful AS mark_doubtful, base.review_options AS review_options, base.result_type AS result_type FROM {quiz_node_properties} base WHERE (base.vid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => 4858 ) in EntityAPIController->query() (line 193 of /home/customer/www/test.domain.com/public_html/sites/all/modules/entity/includes/entity.controller.inc).
The website encountered an unexpected error. Please try again later.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

5.8

Component

Code - Quiz core

Created by

πŸ‡§πŸ‡ͺBelgium pureh2o

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @pureh2o
  • πŸ‡ΊπŸ‡ΈUnited States djdevin

    On the project page under "Upgrading from 7.x-4.x", I believe the issue is https://www.drupal.org/node/2812685#comment-11702775 β†’

    If you are running MySQL 5.7, Drupal 7 core requires a patch to do certain upgrades correctly.

  • πŸ‡§πŸ‡ͺBelgium pureh2o

    Thank you,

    I applied this patch https://www.drupal.org/files/issues/2022-06-01/2615496-83.patch β†’ since my D7 is running on PHP 7.4 and MySql 5.7 but I still have the following errors while running drush updatedb

    [code]
    Cannot add unique key result_answer to table quiz_node_results_answers: unique key already exists. [error]
    Performed update: quiz_update_7501 [ok]
    Cannot add field quiz_long_answer_user_answers.result_answer_id: field already exists. [error]
    Performed update: long_answer_update_7500 [ok]
    SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one [error]
    auto column and it must be defined as a key
    Performed update: truefalse_update_7500 [ok]
    Cannot add field quiz_short_answer_user_answers.result_answer_id: field already exists. [error]
    Performed update: short_answer_update_7500 [ok]
    Cannot add field quiz_multichoice_user_answers.result_answer_id: field already exists. [error]
    Performed update: multichoice_update_7502 [ok]
    Cannot add field quiz_matching_user_answers.result_answer_id: field already exists. [error]
    Performed update: matching_update_7501 [ok]
    'all' cache was cleared. [success]
    Finished performing updates. [ok]
    [/code]

    Could you please help me? as I do not know what else to do.

  • πŸ‡ΊπŸ‡ΈUnited States djdevin

    From the "field already exists"

    It looks like you did not restore back the database and run it again after applying the core patch. This is necessary for that upgrade to work.

Production build 0.69.0 2024