PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed}

Created on 20 May 2011, about 13 years ago
Updated 24 June 2023, 12 months ago

Next Steps:

--
My client is populating nodes with data, and every now and then they get this error:

Notice: Trying to get property of non-object in file_field_presave() (line 221 of /httpdocs/modules/file/file.field.inc).
Notice: Undefined property: stdClass::$uri in file_save() (line 575 of /httpdocs/includes/file.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1305820825 ) in drupal_write_record() (line 6776 of /httpdocs/includes/common.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1305820825 ) in drupal_write_record() (line 6776 of /httpdocs/includes/common.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1305820825 ) in drupal_write_record() (line 6776 of /httpdocs/includes/common.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1305820825 ) in drupal_write_record() (line 6776 of /httpdocs/includes/common.inc).

I've only found reference to the same PDOException and initial notice here:

http://drupal.org/node/924228#comment-4422726

Effectively, it looks like Drupal is trying to save a file, but there's no filename or filesave, so it's failing as a duplicate of the first time this happened (and was stored in the DB).
I think the PDOException is just a symptom, and the real problem is that an invalid file object is being passed along.

I can't be sure whether my client is trying to upload/delete/change a file, or just entering text data into other fields, but this comes up frequently and seemingly at random.

The easiest way to reproduce this error is:

  1. Add an image field into a node
  2. Create a new node and upload an image to its node
  3. Delete the image from the file system (Not through the Drupal UI)
  4. Try to upload the same image into another node
πŸ› Bug report
Status

Closed: duplicate

Version

8.0 ⚰️

Component
File moduleΒ  β†’

Last updated 3 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom ClaudeS-1

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
Production build 0.69.0 2024