Add fields to module database

Add fields to module database

โดย 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?!

การประเมินโดยเฉลี่ย: -
In reply to Eliasz Eliyahu

Re: Add fields to module database

โดย 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

โดย Davo Smith -
รูปภาพของCore developers รูปภาพของParticularly helpful Moodlers รูปภาพของPeer reviewers รูปภาพของ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

โดย 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

โดย 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

การประเมินโดยเฉลี่ย: -