Upgrade from 1.9 to 2.0 error writing to database

Upgrade from 1.9 to 2.0 error writing to database

by Lei Zhang -
Number of replies: 6

I was trying to upgrade a moodle site from 1.9 to 2.0 with some real data, it failed half way through mod_folder upgrades and I got the following errors:

 

Debug info: Duplicate entry '2029' for key 'mdl_resoold_old_uix'

INSERT INTO mdl_resource_old (oldid, course, name, type, reference, intro, introformat, alltext, popup, options, timemodified, cmid)

SELECT r.id, r.course, r.name, r.type, r.reference, r.summary, 0, r.alltext, r.popup, r.options, r.timemodified, cm.id

FROM mdl_resource r

LEFT JOIN mdl_course_modules cm ON (r.id = cm.instance AND cm.module = ?)

[array (

0 => '13',

)]

Stack trace:

  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 682 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 252 of /mod/resource/db/upgradelib.php: call to mysqli_native_moodle_database->execute()
  • line 46 of /mod/folder/db/upgradelib.php: call to resource_20_prepare_migration()
  • line 39 of /mod/folder/db/install.php: call to folder_20_migrate()
  • line 468 of /lib/upgradelib.php: call to xmldb_folder_install()
  • 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()

any ideas?

 

Thanks in advance,

 

Lei

Average of ratings: -
In reply to Lei Zhang

Re: Upgrade from 1.9 to 2.0 error writing to database

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Lei,

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

I suppose this means you have non-core plugins in your moodle 1.9 site? Try to remove them before doing the upgrade.

Joseph

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: Upgrade from 1.9 to 2.0 error writing to database

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You are wrong here Joseph.

upgrade_core() just does the core tables in lib/db/install.xml and upgrade.php.

upgrade_noncore() does all the other datbase talbes which all belong to different plugins. Some of those plugins are part of the standard Moodle release.

(I know people often use core to mean core + plugins in the standard release, but really that is sloppy usage.)

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Upgrade from 1.9 to 2.0 error writing to database

by Lei Zhang -

@Joseph, thanks for your advice. I'll try an upgrade without non-standard plugins.

@Tim, thanks.

One more question, is there anyway to tell which plugin breaks the upgrade process? From my debug info, entry '2029' is a youtube link, can I assume it's a plugin that use this resource break my upgrade?

In reply to Lei Zhang

Re: Upgrade from 1.9 to 2.0 error writing to database

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The problem is occurring in the upgrade from the old 'resource' module to the new 'folder module'. In Moodle 1.9 all the different types of resource were different sub-types of the 'resource' module. In Moodle 2.0 they have been made into completely separate modules, which solves a number of problems. So, the problem is in the upgrade from the old mod/resource/subtype/directory to the new mod/folder.

To find the problem row in your old Moodle 1.9 database, you need to look at the mdl_resource row with id = 2029. Alternatively, you could try going to the URL .../mod/resource/view.php?r=2029 to see it in your browser.

In reply to Tim Hunt

Re: Upgrade from 1.9 to 2.0 error writing to database

by John Reese -

Hi Tim,

Once we go to that page through the url, then what?

what do we do to fix it?

sorry, I don't understand.

Thanks

In reply to John Reese

Re: Upgrade from 1.9 to 2.0 error writing to database

by Chris Fryer -

I experienced this error today.  It seems to be caused by having more than one record in the mdl_course_modules table referencing the same resource.

The error message will tell you the id of the resource that is referenced more than once.  Use the following SQL to locate it in your course:

SELECT r.id, r.course, r.name, r.type, r.reference, cm.id as cmid
FROM mdl_resource r
LEFT JOIN mdl_course_modules cm
ON (r.id = cm.instance)
WHERE r.id = <resource_id>;

Substitute the "duplicate entry" id number for <resource_id> above.  In the OP's case, this is '2029'.

Run the SQL in your database client.  You should get a result set like the following:

+-------+--------+------------------------+------+------------------------+-------+
| id    | course | name                   | type | reference              | cmid  |
+-------+--------+------------------------+------+------------------------+-------+
| 39090 |    835 | Exercise Suggestions 6 | file | estex06suggestions.htm | 50100 |
| 39090 |    835 | Exercise Suggestions 6 | file | estex06suggestions.htm | 50122 |
+-------+--------+------------------------+------+------------------------+-------+
2 rows in set (0.00 sec)

Inspect the list of resources in that course by crafting a URL from the "course" field, e.g. http://yourmoodle.ac.uk/mod/resource/index.php?id=835

Search in the page for the text in the "name" column, in my case "Exercise Suggestions 6".  The URL of the resource's link will tell you which cmid is in use, e.g. https://yourmoodle.ac.uk/mod/resource/view.php?id=50122

As long as there is only one link to the resource in the resource/index.php page, the other coursemodule record is safe to delete. So in my case, the following SQL deleted the record:

delete from mdl_course_modules where id = 50100;
Query OK (1 row affected );

Proceed with the upgrade as before.  It will pick up where you left off.