You are here

function entityreference_update_7002 in Entity reference 7

Make the target_id column NOT NULL.

File

./entityreference.install, line 140

Code

function entityreference_update_7002() {
  if (!module_exists('field_sql_storage')) {
    return;
  }
  foreach (field_info_fields() as $field_name => $field) {
    if ($field['type'] != 'entityreference') {

      // Not an entity reference field.
      continue;
    }
    if ($field['storage']['type'] !== 'field_sql_storage') {

      // Field doesn't use SQL storage, we cannot modify the schema.
      continue;
    }
    $table_name = _field_sql_storage_tablename($field);
    $revision_name = _field_sql_storage_revision_tablename($field);
    db_change_field($table_name, $field_name . '_target_id', $field_name . '_target_id', array(
      'description' => 'The id of the target entity.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
    ));
  }
}