WD php: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'image__teaser__file_image' for key [error]
'PRIMARY': INSERT INTO {file_display} (name, weight, status, settings) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1,
:db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
[:db_insert_placeholder_0] => image__teaser__file_image
[:db_insert_placeholder_1] => 5
[:db_insert_placeholder_2] => 1
[:db_insert_placeholder_3] => a:1:{s:11:"image_style";s:6:"medium";}
)
in drupal_write_record() (line 7106 of /Users/shenliang/Sites/drupal7/includes/common.inc).
Cannot modify header information - headers already sent by (output started at /opt/local/lib/php54/pear/drush/includes/output.inc:37) [warning]
bootstrap.inc:1212
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'image__teaser__file_image' for key 'PRIMARY': INSERT INTO {file_display} (name, weight, status, settings) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
[:db_insert_placeholder_0] => image__teaser__file_image
[:db_insert_placeholder_1] => 5
[:db_insert_placeholder_2] => 1
[:db_insert_placeholder_3] => a:1:{s:11:"image_style";s:6:"medium";}
)

Comments

ParisLiakos’s picture

Project: D7 Media » File Entity (fieldable files)

This table belongs to file entity.
So you uninstalled file_entity and when you re enabled got this?

shenzhuxi’s picture

Status: Active » Closed (cannot reproduce)

sorry I should post it to media module.

ParisLiakos’s picture

Status: Closed (cannot reproduce) » Active

Why media? this table is created by this module and it is being filled up by this as well..

shenzhuxi’s picture

It only happens when I uninstall and re-enable media module.

ParisLiakos’s picture

Project: File Entity (fieldable files) » D7 Media

OK, getting this back to media then

nerilka’s picture

I had the same issue : installed media and uninstalled it, then install it again => Bam! Warning!
After reading this, I have unintalled Media and File entity, then enabled them again and now I don't have anymore the warning and it seems working right...
I should precise, I did this with the 7.x-2.0-unstable7 version.

OnkelTem’s picture

Title: Uninstallation will remain two records in file_display and cause error for re-enable this module » PDOException when installing media module: druplicate entries in {file_display}

The full message text is:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'image__teaser__file_image' for key 'PRIMARY': INSERT INTO {file_display} (name, weight, status, settings) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => image__teaser__file_image [:db_insert_placeholder_1] => 5 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => a:1:{s:11:"image_style";s:6:"medium";} ) in drupal_write_record() (line 7106 of /var/www/lib/d7_dev/core/includes/common.inc).

Steps to reproduce:

  1. Enable file_entity module
  2. Configure Image's bundle file display and Save. Behind the scene {file_display} table is updated:
    *************************** 1. row ***************************
        name: image__preview__file_image
      weight: 5
      status: 1
    settings: a:1:{s:11:"image_style";s:15:"media_thumbnail";}
    ..
    *************************** 3. row ***************************
        name: image__teaser__file_field_file_default
      weight: 0
      status: 0
    settings: N;
    *************************** 4. row ***************************
        name: image__teaser__file_field_file_rendered
      weight: 0
      status: 0
    settings: a:1:{s:14:"file_view_mode";s:7:"default";}
    *************************** 5. row ***************************
        name: image__teaser__file_field_file_table
      weight: 0
      status: 0
    settings: N;
    *************************** 6. row ***************************
        name: image__teaser__file_field_file_url_plain
      weight: 0
      status: 0
    settings: N;
    *************************** 7. row ***************************
        name: image__teaser__file_field_image
      weight: 0
      status: 0
    settings: a:2:{s:11:"image_style";s:0:"";s:10:"image_link";s:0:"";}
    *************************** 8. row ***************************
        name: image__teaser__file_image
      weight: 0
      status: 1
    settings: a:3:{s:11:"image_style";s:6:"medium";s:3:"alt";s:0:"";s:5:"title";s:0:"";}
    8 rows in set (0.00 sec)
  3. Now enable Media module and get the PDOException

The problem is in media_install() function as it tries to insert default records which are already there.

function media_install() {
  ...
  $default_image_styles = array(
    'preview' => 'media_thumbnail',
    'teaser' => 'medium',
    'full' => 'large',
  );
  ...
  foreach ($default_image_styles as $view_mode => $image_style) {
    $display_name = 'image__' . $view_mode . '__file_image';
    $display = array(
      'api_version' => 1,
      'name' => $display_name,
      'status' => 1,
      'weight' => 5,
      'settings' => array('image_style' => $image_style),
      'export_type' => NULL,
    );
    file_display_save((object) $display);
  }
}
OnkelTem’s picture

Priority: Normal » Major
xtfer’s picture

Title: PDOException when installing media module: druplicate entries in {file_display} » Duplicate entries in file_display table cause PDO Exception on installation

I'm tempted to think this should be fixed in file_entity's file_display_save() method, but failing that, checking if they exist first would be helpful.

xtfer’s picture

Status: Active » Needs review
StatusFileSize
new1.5 KB
dave reid’s picture

Issue tags: +7.x-2.0 alpha blocker
aaron’s picture

Status: Needs review » Reviewed & tested by the community

This does the job. Thanks a lot!

devin carlson’s picture

devin carlson’s picture

Status: Reviewed & tested by the community » Fixed

Committed #10 to 7.x-2.x.

Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.