When I try and import nodes with file fields, I get the following error:
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] => 1936 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 657 of [website path]/includes/file.inc)
This issue previously highlighted the same error: https://www.drupal.org/node/1980918.
Comments
Comment #1
Joe_Smith commentedComment #2
Joe_Smith commentedLooks like a conflict with the filefield_paths module.
I solved this problem for myself in the end by turning off the filefield_paths module before doing the import and then just turning it on after the import was complete.
Perhaps there was an issue because the files attached to the nodes being imported were given path names by the filefield_paths module that contained field values from the node itself. e.g. a node of type city might have a file field and a name field (like London) - the path to that file would be "sites/default/files/city_files/london/file.pdf".
The filefield_paths module is recommended, for example by Acquia (https://www.acquia.com/blog/preventing-drupal-headaches-file-field), for Drupal 7 users so resolving this conflict may help other users. I'll leave this issue open for that reason but feel free to close if this is working as intended.
Comment #3
dureaghin commentedI also get the following error when I trying to import nodes with attached files (PDF) and I'm not using filefield_paths module. I'm using drush command to import data.
Comment #4
dureaghin commentedFixed,
Add to line 896 and 1020:
$dataset_node->{$file_field_data}[LANGUAGE_NONE][$file_array_key]['display'] = 1;