When trying to edit a field collection I get the error:

Attempt to update field Fieldname failed: Cannot add index field_fieldname_revision_id to table field_data_field_fieldname: index already exists..


nostop8’s picture

Status: Active » Needs work

I confirm same bug (using field collection 7.x-1.x). I have no idea why and when it happen, but my field collection instances does not have indexes inside data column. That's why it throws error on field collection save.

I made a small workaround which will allow you to save your field collection. The only place I could add indexes was to field data was hook_field_update_forbid (from its name it does not seem that it serves for these needs, but another hook hook_field_read_field which is there too does not allow to change the data... strange behavior from drupal core... :( ).

Anyway, here's what I made:

 * Implements hook_field_update_forbid().
function hook_field_update_forbid(&$field, &$prior_field, &$has_data) {
  if($prior_field['module'] == 'field_collection') {
    if(empty($prior_field['indexes'])) {
      $prior_field['indexes'] = array(
        'revision_id' => array('revision_id')

You will need this only once, to save your collection field. Then you won't need it anymore for this specific field collection.

This is just a workaround. Guys from Field Collection team need to find what's the problem if this strange behavior. Maybe it has something to do with the nested field collections? I do not have any idea and do not have time to test it. But the issue exists!!

tuccio’s picture

Hi thank you. The issue first seems to occurs when revisions are enabled, but even after disabling revisions then the issue persists.

nostop8’s picture

Issue summary: View changes
Status: Needs work » Needs review
tuccio’s picture

Title: annot edit field collections: Attempt to update field Fieldname failed: » Cannot edit field collections: Attempt to update field Fieldname failed:
tuccio’s picture

Is this a related issue? https://drupal.org/node/2141781

Dane Powell’s picture

Status: Needs review » Closed (duplicate)