Add fields to module database

Add fields to module database

by Eliasz Eliyahu -
Number of replies: 5

I found this:

http://moodlever.blogspot.com/2011/02/add-field-to-module-database.html?showComment=1305552829464#c4606654278267117976

My questions are in comments on blogspot. This is it:

Why in PHPMYADMIN in table mdl_mymodule the new fields are not available but in XMLDB Editor are available?!

Average of ratings: -
In reply to Eliasz Eliyahu

Re: Add fields to module database

by Eliasz Eliyahu -

upgrade.php not upgrade db tables ;( I don't know why... I fix it editing db/install.xml paste into code from xmldb editor (XMLDB > MyModule > View edited) and reinstall my newmodule. Thanks for helping smile

In reply to Eliasz Eliyahu

Re: Add fields to module database

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Did you also update your plugins version number, in version.php, make sure you put the same version number in the if statement in upgrade.php and visit the notifications page as admin? As for your original question, you can certainly add fields using phpmyadmin, but if you then distribute your plugin, other users will not get the new field.
In reply to Davo Smith

Re: Add fields to module database

by Eliasz Eliyahu -

Unfortunetely. If I updated plugin version in upgrade.php and version.php in Notification is everything allright but mysql not create new fields. In XMLDB new fields are.

In reply to Eliasz Eliyahu

Re: Add fields to module database

by Justin Wyllie -

Just to check you copied the code from the XMLDB editor into upgrade.php before running the upgrade - not install.xml, which it builds automatically?

So in upgrade.php you have something like:

if ($result && $oldversion < newversionumber) {

$table = new xmldb_table('tablename');
$field = new xmldb_field('newfieldname', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'settings');

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

 

upgrade_plugin_savepoint(true, newversionnumber, 'plugin', 'subplugin');//copy this from the XMLDB editor
}

?

J