1

I have a custom entity that was create a long time ago. Now we want to update the schema to remove a property (not a field) that was defined in the original schema.

I've reviewed the Drupal API for managing schema for custom entities and I don't see anything that allows me to remove the column during a hook_update_N function.

Am I missing something obvious here?

1 Answer 1

4

You're looking for db_drop_field(). Although it's called a "field" here, it's essentially the remove-a-column-from-the-DB-table function.

Example from filter_update_7005():

// Drop the roles field from the {filter_format} table.
db_drop_field('filter_format', 'roles');
4
  • 2
    Just a note - the hook_schema() implementation will need to be updated too, to remove the same field, and there might be some other things to change depending on what modules are installed (e.g. if that property is used in a View, if there are hook_entity_property_info() implementations referring to it, other code, etc). Adding drupal_flush_all_caches() at the end of the update function would be a good idea too
    – Clive
    Commented Feb 9, 2016 at 18:16
  • @Clive I thought the caches will always be flushed after updates are finished. Is it really necessary to call drupal_flush_all_caches() manually?
    – Elin Y.
    Commented Feb 9, 2016 at 21:05
  • 1
    I've just checked it up, and yes, after updates are finished, drupal flushes the caches: update_finished
    – Elin Y.
    Commented Feb 9, 2016 at 21:15
  • @ЕлинЙ. Yep you're right, withdrawn ;)
    – Clive
    Commented Feb 9, 2016 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.