I created a field collection and added it to a content type. After saving content with data in the field collection, I get the following error:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'uuid' in 'field list': INSERT INTO {field_collection_item} (revision_id, field_name, archived, uuid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => field_finishes [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => e114057b-3912-4faf-b996-a5bc03f7ccd3 ) in drupal_write_record() (line 7106 of /var/www/html/drupal-7.20/includes/common.inc).

I have run update.php and cleared caches.

Comments

acouch’s picture

I think this happens because some entities don't have uuids associated with them. I got a similar error with organic groups. I'm posting it here in case anyone else has the same issue:

Notice: Undefined index: uuid in entity_get_uuid_by_id() (line 405 of /var/www/EXAMPLE/webroot/sites/all/modules/uuid/uuid.entity.inc).
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS FROM og_membership t WHERE (id IN ('3'))' at line 1: SELECT t.id AS id, t. AS FROM {og_membership} t WHERE (id IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => 3 ) in entity_get_uuid_by_id() (line 421 of /var/www/EXAMPLE/webroot/sites/all/modules/uuid/uuid.entity.inc).

In this case og_membership does not have a uuid. I don't know enough about this module to know if that is a bug that should be addressed elsewhere. However the attached patch keeps the module from looking up a uuid on an entity if it doesn't have a uuid key.

btopro’s picture

was just able to throw this when doing a restws call for nodes in json format.

Notice: Undefined index: uuid in entity_get_uuid_by_id() (line 405

was thrown in its place. Looks identical to the issue in #1

EDIT: And the patch supplied in issue 1 resolved this for me as well. This seems like a more sensible approach to verifying that a uuid is set

fago’s picture

Title: Unknown column 'uuid' in 'field list' » UUID modules breaks field collection
Priority: Normal » Major

I ran into this as well. When field collection got installed (after UUID) it did not create the UUID column, while UUID alters in the column later on. This results in the above error when drupal_write_record() fails to write to the not existing UUID column.

I guess UUID module would have to detect when field collection is enabled and adjust is schema after installation.

As interim fix I used an update function like the following:

**
 * Fix field collection UUID problems.
 */
function foo_update_700X() {
  $entity_type = 'field_collection_item';
  $info = entity_get_info($entity_type);
  $field = uuid_schema_field_definition();

  if (!db_field_exists($info['base table'], $info['entity keys']['uuid'])) {
    db_add_field($info['base table'], $info['entity keys']['uuid'], $field);
    db_add_index($info['base table'], $info['entity keys']['uuid'], array($info['entity keys']['uuid']));
  }
  if (!empty($info['revision table']) && !empty($info['entity keys']['revision uuid'])) {
    if (!db_field_exists($info['revision table'], $info['entity keys']['revision uuid'])) {
      db_add_field($info['revision table'], $info['entity keys']['revision uuid'], $field);
      db_add_index($info['revision table'], $info['entity keys']['revision uuid'], array($info['entity keys']['revision uuid']));
    }
  }
}
fago’s picture

Title: UUID modules breaks field collection » UUID module breaks field collection
el7cosmos’s picture

Got error with message entity which didn't have uuid entity keys

chertzog’s picture

#1 works for me with OG.

jsacksick’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new552 bytes
new952 bytes

I also experienced issues (doesn't seem to be the same message though), See http://cl.ly/image/2z0X2W163o2n, The attached patch fixes the issue. I also think the uuid module should implement the hook_flush_caches() to create the missing table columns... Attaching two patches.

Paul B’s picture

I get the same error with the RESTful Web Services module.
The module does this in getResourceReference:

    if (module_exists('uuid') && entity_get_info($resource)) {
      $ids = entity_get_uuid_by_id($resource, array($id));
      if ($id = reset($ids)) {
        $return['uuid'] = $id;
      }
    }

The patch doesn't help. Maybe entity_get_uuid_by_id() should check if $info['entity keys']['uuid'] actually exists.

btopro’s picture

Title: UUID module breaks field collection » UUID module breaks entities lacking uuid support
StatusFileSize
new1.29 KB

This is not specific to field collections. Patch is a combination of the original proposed solution, the patch in #8 uuid-fix-field-collection-1927474-7.patch and an additional location that this needed to be accounted for in order to work for me. I have this working in production as it was failing on a restWS calls when utilizing organic groups because the group membership entity lacks uuid's as well (I think). This is an obscure but important issue to resolve, especially when dealing with more complex entity driven sites.

nbouhid’s picture

StatusFileSize
new2.46 KB

Patch from #9 doesn't apply cleanly on version: 7.x-1.0-alpha4.

This patch should do the trick.

Have anyone tested this issue on the 7.x-1.0-alpha5 version?

Status: Needs review » Needs work

The last submitted patch, 10: uuid-fix-empty-uuids-1927474-10.patch, failed testing.

Kazanir’s picture

StatusFileSize
new1.92 KB

Rerolled the patch in #9 to correctly check for the enabling of UUID on the entity info as well as the actual presence of the appropriate entity info key.

tomdavidson’s picture

confrim #13 worked for me and node_export

btopro’s picture

Status: Needs work » Needs review

didnt test #13 but looks like it builds on the fixes in #9. bumping to needs review

skwashd’s picture

Status: Needs review » Closed (duplicate)

Thanks everyone for your work on this issue, but it is a duplicate of #2356305: Some contrib entities has no support for UUID, let's skip them., which is currently RTBC. Let's run with that one.