Create missing schema fields

Public

If you're working on a module and want to add some additional fields to existing tables in database, add those fields to hook_schema and run snippet above.

</> CopyGet raw version
php
  1. $schema = drupal_get_complete_schema(TRUE);
  2. foreach ($schema as $table_key => $table) {
  3. if (!isset($table['fields']) || empty($table['fields'])) {
  4. continue;
  5. }
  6. foreach ($table['fields'] as $field_key => $field) {
  7. if (!db_field_exists($table_key, $field_key)) {
  8. db_add_field($table_key, $field_key, $field);
  9. }
  10. }
  11. }