PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘field_xxx_display’ cannot be null:

If you are using Features module to import/export sample data like for kickstart data for your new feature. If you are using the newest version dependent modules – uuid and uuid_featurs(7.x-1.0-alpha or above) of the Feature module, then you will get the following error at the time importing sample data that contains field referencing asset such as image, video,etc:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘field_xxx_display’ cannot be null:

The issue is that there appears to have a bug in uuid_features module of the newest version that strips away attribute ‘display’ from the sample import. One solution is to reattach back the missing attribute just before the sample data is saved. To do so, we use hook_node_presave() as following:

function MODULE-NAME_node_presave($node) {
    //fix  for sample data import where 'display' is striped away for field_xxx causing db syntax error at node_save
    if($field_instance = field_get_items('node', $node, 'field_xxx')){
        foreach($field_instance as $key => $field_ins){
            $node->field_xxx['und'][$key]['display'] = 1;
        }
    }

Here, in line 3, the field instance is retrieved for the node being imported. If it exists, then in line 4, we go through all of the instances of that field and add the attributed ‘display’ that was striped away by uuid_features module. Note, that the word ‘display’ is removed from ‘field_xxx_display’ as mentioned in the error message because its added by Drupal to store the data

2 thoughts on “PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘field_xxx_display’ cannot be null:

  1. Thank you! I don’t understand why there’s nothing in any Drupal issues queues that I could find that address this problem. It seems like a common enough use case, I can’t understand why it hasn’t been addressed. I’m actually using the Node Export module rather than UUID Features, which makes me wonder if the issue is with Features or UUID rather than one of these modules. I’ll have to investigate further. In the meantime, have you submitted any bug reports on drupal.org? Issues like this need to be brought to the attention of the maintainers or at least the community if you want them to get fixed on a global level.

    • Bobo. I am sorry I haven’t reported. Looking into code, I am under impression that this a major issue and they are working on it…i also agree, i should still report

Leave a Reply

Your email address will not be published. Required fields are marked *