I'm dealing building several modules that should cope with automatic creation of content synchronized with external sources. The whole process is automatized, e.g. everything had been created programatically. My content type has and image field attached to it. When appempting to create a node without defining what this image field should contain (and it should stay empty), I fall with exception:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048
Column 'fid' cannot be null: INSERT INTO {file_usage} (fid, module, type, id, count)
VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4);
Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => file [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] => 264 [:db_insert_placeholder_4] => 1 )
in file_usage_add() (line 657 of /usr/local/drupal7/includes/file.inc).
When on hook_node_presave I'm adding an image to this field all works correctly, but I would like to leave this field empty, that may affect the rest of development process.
If I create the node type programatically but add the image field manually -- all works ok. I tried it, then printed the definition of this field using function field_info_field()
and copied some values of there into my code, but it didn't help.
Here is my image field definition:
...
'field_member_photo' => array(
'label' => t('Member Photo'),
'field_name' => 'field_member_photo',
'type' => 'image',
'module' => 'image',
'active' => '1',
'locked' => '0',
'cardinality' => '1',
'deleted' => '0',
'widget' => 'image_image',
'entity_types' => array('node'),
'settings' => array('uri_scheme' => 'public', 'default_image' => 0,),
),
...
Would appreciate any thought about how to solve this problem.