0

Attaching image files to nodes programmatically in Drupal 7

Hi,when I accroding this artical ,but met an pdo error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'field_pr_quotation_file_display' cannot be null: INSERT INTO {field_data_field_pr_quotation_file} (entity_type, entity_id, revision_id, bundle, delta, language, field_pr_quotation_file_fid, field_pr_quotation_file_display, field_pr_quotation_file_description) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 136 [:db_insert_placeholder_2] => 249 [:db_insert_placeholder_3] => purchase_request [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 24 [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => ) in field_sql_storage_field_storage_write() (line 451 of D:\www\Sites\pr\modules\field\modules\field_sql_storage\field_sql_storage.module).

4

1 回答 1

0

https://drupal.stackexchange.com/questions/69684/how-to-assign-value-from-one-file-field-to-another-programmatically根据此处,我添加 display =1

$field_file = (array) $file;
$field_file['display'] = 1;

dpm($file,'field_pr_ref_quotation_file');
$node->field_pr_ref_quotation_file[LANGUAGE_NONE][] = $field_file;
于 2013-06-13T15:27:25.937 回答