"Multiple records found, only one record expected" during upgrade to 2.0.1+

"Multiple records found, only one record expected" during upgrade to 2.0.1+

by Jonathan King -
Number of replies: 12

Hi, I'm testing the upgrade from 1.9.8 to 2.0.1 and am hitting this error.  I cannot uninstall Workshop from my existing Moodle install, and am trying to do an upgrade to 2.0.1 by migrating the data to a new 2.0.1 instance and letting Moodle do the database and moodledata upgrade. Any thoughts on how to solve this? We do have some Workshop data in Moodle, but I'm willing to drop it all for a successful upgrade.

Thanks so much for considering this issue,

-jonathan king

 

mod_workshop

Copying submissions

Multiple records found, only one record expected.

More information about this error

Debug info: SELECT cm.*, m.name, md.name AS modname

FROM {course_modules} cm

JOIN {modules} md ON md.id = cm.module

JOIN {workshop} m ON m.id = cm.instance

 

WHERE m.id = :instance AND md.name = :modulename

 

[array (

'instance' => '8',

'modulename' => 'workshop',

)]

Stack trace: line 1266 of \lib\dml\moodle_database.php: dml_multiple_records_exception thrown

line 1407 of \lib\datalib.php: call to moodle_database->get_record_sql()

line 253 of \mod\workshop\db\upgradelib.php: call to get_coursemodule_from_instance()

line 124 of \mod\workshop\db\upgrade.php: call to workshop_upgrade_submissions()

line 490 of \lib\upgradelib.php: call to xmldb_workshop_upgrade()

line 265 of \lib\upgradelib.php: call to upgrade_plugins_modules()

line 1352 of \lib\upgradelib.php: call to upgrade_plugins()

line 290 of \admin\index.php: call to upgrade_noncore()

Average of ratings: -
In reply to Jonathan King

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by Colin Fraser -
Picture of Documentation writers Picture of Testers

The structure of backup files are completely different in Moodle 2.0 than they were in v1.9.x. This has created a number of problems which are still in the process of being resolved. There has been developed a backup converter, which is not free of charge, but it depends on using proprietal software not available to everyone at http://conversionthingy.net/ This is the first of them and so I expect that others will follow soon.

In reply to Colin Fraser

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Colin, this has nothing to do with backups. It is upgrade 1.9 -> 2.0 issue
In reply to David Mudrák

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by Colin Fraser -
Picture of Documentation writers Picture of Testers

So it does, after reading it properly..ha! So many backup issues I am in a rut!!!! Trying to look at one question and answer another.. now I got to find the one I was supposed to reply to...tongueout

Best thing with upgrades from 1.9 to 2.0, don't do them. Fresh install is the ONLY realistic option. Read this from the Beginning Moodle 2.0 Administration doc.

In reply to Jonathan King

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Hi Jonathan,

you seem to have data integrity corrupted in your database. It looks to me like if you have either more workshop instances sharing the same course_module (the course_module is a slot in a course that activity modules live in) or there are two course_modules containing the same workshop instance.

Please run the following SQL query at your 1.9 database before you start upgrade

SELECT cm.*, m.name, md.name AS modname
  FROM mdl_course_modules cm
  JOIN mdl_modules md ON md.id = cm.module
  JOIN mdl_workshop m ON m.id = cm.instance
 WHERE m.id = 8 AND md.name = 'workshop';

and report me results here.

In reply to David Mudrák

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by Jonathan King -

David,

Thank you for your suggestion. Unfortunately, while one row did seem to be affected by the SQL statement, the end result of a fresh migration were the same as listed above. Here is what SQL returned:

+-------+--------+--------+----------+---------+----------+------------+-------+--------+---------+------------+-----------+------------+------------------+-----------------------------+----------+| id    | course | module | instance | section | idnumber | added      | score | indent | visible | visibleold | groupmode | groupingid | groupmembersonly | name                        | modname  |+-------+--------+--------+----------+---------+----------+------------+-------+--------+---------+------------+-----------+------------+------------------+-----------------------------+----------+| 17297 |    287 |     17 |        8 |    3276 | NULL     | 1262893035 |     0 |      0 |       1 |          1 |         0 |          0 |                0 | Letters To A Representative | workshop |+-------+--------+--------+----------+---------+----------+------------+-------+--------+---------+------------+-----------+------------+------------------+-----------------------------+----------+1 row in set (0.11 sec)

When I run the SQL statement AFTER receiving this error, it returns something slightly different:

+-------+--------+--------+----------+---------+----------+------------+-------+--------+---------+------------+-----------+------------+------------------+------------+---------------------------+----------------+--------------------+---------------+----------------+------------------+-----------------------------+----------+| id    | course | module | instance | section | idnumber | added      | score | indent | visible | visibleold | groupmode | groupingid | groupmembersonly | completion | completiongradeitemnumber | completionview | completionexpected | availablefrom | availableuntil | showavailability | name                        | modname  |+-------+--------+--------+----------+---------+----------+------------+-------+--------+---------+------------+-----------+------------+------------------+------------+---------------------------+----------------+--------------------+---------------+----------------+------------------+-----------------------------+----------+| 17015 |    770 |     17 |        8 |    4414 | NULL     | 1262893035 |     0 |      0 |       0 |          1 |         0 |          0 |                0 |      0 |                      NULL |              0 |                  0 |        0 |              0 |                0 | Letters To A Representative | workshop || 17297 |    287 |     17 |        8 |    3276 | NULL     | 1262893035 |     0 |      0 |       1 |          1 |         0 |          0 |                0 |      0 |                      NULL |              0 |                  0 |        0 |              0 |                0 | Letters To A Representative | workshop |+-------+--------+--------+----------+---------+----------+------------+-------+--------+---------+------------+-----------+------------+------------------+------------+---------------------------+----------------+--------------------+---------------+----------------+------------------+-----------------------------+----------+2 rows in set (0.00 sec)

Is there a way to just delete the Workshop data in the SQL database directly? Can I just drop the Tables? Which Tables? Thanks so much for your insight on this!

-Jonathan

In reply to Jonathan King

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Hm, this is really weird. Your 1.9 database seems to be all right but somewhere during the upgrade, an invalid course_module record is created.

If you are happy to upgrade your site without workshops, you can uninstall the whole Workshop module in 1.9 before you start upgrade. Note that it will drop all workshop data, tables etc.

Alternatively, please help us to debug this behaviour. Just after you replace Moodle source code files with the new version - but before you actually start the upgrade procedure - please go and edit the file mod/workshop/db/upgrade.php. Find a line near 60 reading

//===== end of 1.9.0 upgrade line ======//

and insert the following code right after it:

if ($oldversion < 2007101510) {
    die('Upgrade procedure halted before mod_workshop turn');
}

Now go and run upgrade. It will halt just before any changes are done with workshop tables yet. Now go and run the SQL query discussed above. Please, let me know the results.

TIA

In reply to David Mudrák

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by Leonildo Costa -

David,

We are also migrating Moodle version 1.9.5+ (Build: 20090902) to 2.0.1+ (Build: 20110204). We got the same error that Jonathan had.

Following the orientation you gave to Jonathan, we added that code to the file mod/workshop/db/upgrade.php and we got the following result:

-->mod_workshop
!! Orphaned assessment records found - cleaning... !!
Upgrade procedure halted before mod_workshop turn

Executing the query proposed we got the following:


id | course | module | instance | section | added | score | indent | visible | groupmode | visibleold | idnumber | groupingid | groupmembersonly | completion | completiongradeitemnumber | completionview | completionexpected | availablefrom | availableuntil | showavailability | name | modname
----+--------+--------+----------+---------+-------+-------+--------+---------+-----------+------------+----------+------------+------------------+------------+---------------------------+----------------+--------------------+---------------+----------------+------------------+------+---------
(0 registro)

Please, let me know how to solve this problem.

Thank's in advance.

In reply to Leonildo Costa

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Ah, grrrr. I found it. There is a really nasty bug in Workshop upgrade code. I am going to work on a patch and will let you know. Meanwhile, please do not try to upgrade. Sorry for that and thanks for helping me to detect this.
In reply to Leonildo Costa

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Hello,

I have a patch that is supposed to fix this. You can either wait until next week for the new Moodle 2.0 build, or apply the patch immediately. I would like to ask you for the second option as that way, you would help to test the patch before it goes into Moodle core.

To apply the patch, you can

  • either download TGZ archive attached to this post (It contains just five modified workshop files that need to be replaced at your Moodle 2.0 server)
  • or download a whole snapshot (in ZIP or TGZ) of the most recent Moodle 2.0 together with the patch incorporated from my github repository (follow the Downloads link at the page)

This issue is now tracked as MDL-26312. Please test if the patched version is able to upgrade for you and let me know - either here or via a comment in the tracker. Thanks a lot in advance.

In reply to David Mudrák

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by Leonildo Costa -

David,

We applied this patch MDL-26312-fix.tgz and we the upgrade worked just fine!

Thank' s  a lot!

PS: Next week we are going to test new Moodle 2.0 build. Then I will report you the upgrade.

In reply to David Mudrák

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by Markus Strobl -

Hello I wanted to update from Moodle 2.1.1+ (Build: 20110831) to an actual version. So I started with version v2.2.11 from the download page and trying to update I get the same message "multiple records..."

 

Can anybody help me? There is no more information in the update window, which records are meant

 

Debug-Info:

Debug info: SELECT * FROM {context} WHERE contextlevel = ?
[array (
0 => 10,
)]
Stack trace:
  • line 1307 of \lib\dml\moodle_database.php: dml_multiple_records_exception thrown
  • line 1269 of \lib\dml\moodle_database.php: call to moodle_database->get_record_sql()
  • line 1249 of \lib\dml\moodle_database.php: call to moodle_database->get_record_select()
  • line 5632 of \lib\accesslib.php: call to moodle_database->get_record()
  • line 6872 of \lib\accesslib.php: call to context_system::instance()
  • line 654 of \lib\setup.php: call to get_system_context()
  • line 20 of \config.php: call to require_once()
  • line 55 of \admin\index.php: call to require()

 

greetings

Markus

In reply to Markus Strobl

Re: "Multiple records found, only one record expected" during upgrade to 2.0.1+

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Hi Markus

on contrary to previous posts above, your problem has nothing to do with the Workshop module. Your Moodle database is corrupted though. There are multiple records for the system context found, whereas only a single record is expected. I can't explain how this could happen to you, or how to fix it.

If you don't have many courses, a good alternative might be to install a fresh new Moodle and backup/restore every course to it.