When a new node is created and no value is supplied to an included media embed field in the content type the following error is generate:

"The website encountered an unexpected error. Please try again later."

and the following exception is logged.

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] => 1350 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 664 of D:\websites\globalengaged7\includes\file.inc).

The new node created OK

If a value is supplied then node saves fine and I dont see the error.

The field by the way is marked as not required.

Comments

martynpanes’s picture

Got to the bottom of this - basically the field exists as a entity type of "file" after being carried over after a drupal 6 to 7 upgrade and the original media content type being "content migrated" - the entity type remains as "file" instead of "media"

martynpanes’s picture

Status: Active » Closed (works as designed)
martynpanes’s picture

lkklkl

freelock’s picture

@Martynpanes how did you resolve this? I think I'm hitting the same issue, site upgraded D6 to D7, can't post new articles without adding media to an optional field, get this error. How did you set the entity type to fix this?

freelock’s picture

For posterity: in our case, field had a default value set, but there was no UI for the media selector or file widgets for setting/changing default values.

To fix, I set the widget to Embedded Media, deleted the default value that appeared, and then set the widget back.

drupalninja99’s picture

#5 worked for me, thanks!

fadgadget’s picture

hello i have the same problem with a video file that i converted D6 to D7. Finding it hard to follow the above. This part-

deleted the default value that appeared

What default value should i be deleting? I dont see anything to delete. Just when i thought i had managed to finally migrate this has thrown me.

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] => 15060 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 661 of /home/onlineba/public_html/includes/file.inc).

my field settings-

Video URL field_videourl File Media file selector

Thanks :hope

fadgadget’s picture

sorted :) I missed the part about enabling embedded media field module. I changed my field widget to this and then noticed that i had the 'require this field' checkbox ticked. I unticked this and then changed the widget back as freelock suggested and all working fine. phew

13rac1’s picture

My steps to correct:

  1. Enable Embedded Media Field
  2. Change the field widget to Embedded Media Field
  3. Delete the default value for the field
  4. Change the field widget back to Media File Selector
krisrobinson’s picture

Component: File entity » Code
Issue summary: View changes

Thank you for #9. Worked for me.

scottybrookie’s picture

#5 and #9 fixed the problem for me as well. Thank you.

couloir007’s picture

I've followed these steps, in fact I've done this on another site with success, but this time around I follow the directions but no Embedded Media Field is available. I've trie uninstalling and reinstalling with no success. Much searching turns up nothing.