I've created a block which is working fine but I need to upgrade the database to add a table.
According to the documentation I can use the XMLDB creator so I did. The code it generates doesn't work.
// Define field id to be added to voucher_courses.
$table = new xmldb_table('voucher_courses');
if(!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
$field = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Conditionally launch add field id.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
Table "voucher_courses" does not exist
Error code: ddltablenotexist
- line 146 of /lib/ddl/database_manager.php: ddl_table_missing_exception thrown
- line 28 of /blocks/voucher/db/upgrade.php: call to database_manager->field_exists()
- line 1005 of /lib/upgradelib.php: call to xmldb_block_voucher_upgrade()
- line 514 of /lib/upgradelib.php: call to upgrade_plugins_blocks()
- line 1857 of /lib/upgradelib.php: call to upgrade_plugins()
- line 694 of /admin/index.php: call to upgrade_noncore()
Sorry if this is a bit of a newbie question but I've hit a brick wall with this.
Cheers
Dave