The web-based user creation from admin/config/development/generate/user is working fine.

However, if I do
drush genu 50
I get a fatal:

WD php: PDOException: SQLSTATE[23000]: Integrity constraint          [error]
violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO
{file_managed} (uid, filemime, filesize, timestamp) VALUES
(:db_insert_placeholder_0, :db_insert_placeholder_1,
:db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
    [:db_insert_placeholder_0] => 84
    [:db_insert_placeholder_1] => image/png
    [:db_insert_placeholder_2] => 0
    [:db_insert_placeholder_3] => 1285603796
)
 in drupal_write_record() (line 6316 of
/home/rfay/workspace/d7git/includes/common.inc).
WD php: Warning: Cannot modify header information - headers already  [warning]
sent by (output started at
/usr/local/lib/drush/includes/drush.inc:871) in drupal_send_headers()
(line 1048 of /home/rfay/workspace/d7git/includes/bootstrap.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (uid, filemime, filesize, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
    [:db_insert_placeholder_0] => 84
    [:db_insert_placeholder_1] => image/png
    [:db_insert_placeholder_2] => 0
    [:db_insert_placeholder_3] => 1285603796
)
 in drupal_write_record() (line 6316 of /home/rfay/workspace/d7git/includes/common.inc).
Drush command could not be completed.                                [error]

Comments

moshe weitzman’s picture

Status: Active » Postponed (maintainer needs more info)

Sorry, I can't reproduce it. I am getting fine user pictures in my generated users (using drush).

rfay’s picture

That's weird. I've tried a bunch of things (like getting drush head). But haven't actually debugged it. I think I even used a clean db. Oh well. Not terribly critical when the web interface works.

okokokok’s picture

I'm working on a custom image import script and I was getting similar errors:

WD node: 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,     [error]
:db_insert_placeholder_2); Array
(
    [:db_insert_placeholder_0] => 0
    [:db_insert_placeholder_1] => 1
    [:db_insert_placeholder_2] => 1291072476
)
 in drupal_write_record() (line 6611 of /var/www/mysite/htdocs/includes/common.inc).
WD php: 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,      [error]
:db_insert_placeholder_2); Array
(
    [:db_insert_placeholder_0] => 0
    [:db_insert_placeholder_1] => 1
    [:db_insert_placeholder_2] => 1291072476
)
 in drupal_write_record() (line 6611 of /var/www/mysite/htdocs/includes/common.inc).
WD php: Warning: Cannot modify header information - headers already sent by (output started at /var/www/mysite/htdocs/sites/all/modules/custom/imgimp/imgimp.module:100) in drupal_send_headers() (line 1028 of            [warning]
/var/www/mysite/htdocs/includes/bootstrap.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] => 1291072476
)
 in drupal_write_record() (line 6611 of /var/www/mysite/htdocs/includes/common.inc).
Drush command could not be completed.     

This was finally fixed when I did not unset file->fid, which I had done in order to try to fix another error which was actually due false expectations of imagemagick's behavior.

Anyway, my comment might be slightly off-topic, but it might just help someone else in the future and this was the only relevant bug report that showed up on d.o.

eclipsegc’s picture

Status: Postponed (maintainer needs more info) » Active

Seen the same behavior in node generation through the UI when a custom file path is on the field

moshe weitzman’s picture

Status: Active » Postponed (maintainer needs more info)

Still can't reproduce the error on users. I have user pictures enabled and they are generating properly.

peter törnstrand’s picture

Same issue here. It only occurs when I have specified a custom "File directory" in my "File field". I tried changing the permissions on "files"-directory to 777, error still occurs.

ldweeks’s picture

I think that this problem may have something to do with the features module. Here is what I did:

  • I installed d7 with a custom install profile.
  • I enabled about 5 custom features, most of which were just content types.
  • I tried to use devel_generate, and I got the following error:
    Notice: Trying to get property of non-object in _file_devel_generate() (line 28 of /Applications/MAMP/htdocs/sb/sites/all/modules/contrib/devel/devel_generate/file.devel_generate.inc).
    Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /Applications/MAMP/htdocs/sb/includes/entity.inc).
    Notice: Trying to get property of non-object in file_field_presave() (line 221 of /Applications/MAMP/htdocs/sb/modules/file/file.field.inc).
    Notice: Undefined property: stdClass::$uri in file_save() (line 575 of /Applications/MAMP/htdocs/sb/includes/file.inc).
    Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /Applications/MAMP/htdocs/sb/includes/entity.inc).
    Notice: Trying to get property of non-object in file_field_presave() (line 221 of /Applications/MAMP/htdocs/sb/modules/file/file.field.inc).
    Notice: Undefined property: stdClass::$uri in file_save() (line 575 of /Applications/MAMP/htdocs/sb/includes/file.inc).
    PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': 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] => 1304454051 ) in drupal_write_record() (line 6776 of /Applications/MAMP/htdocs/sb/includes/common.inc).
  • I then found comment #6 above, and decided to delete all my custom file directory paths in each filefield of the offending content type. I tried devel_generate again, and it worked fine.
  • I then started adding the custom directory paths back into my filefield directories, and devel_generate started working again.
  • Finally, I deleted all my content and reverted all my features back so that nothing was being overridden. I tried devel_generate again, and I got the above error once again.
rfay’s picture

Status: Postponed (maintainer needs more info) » Active

Maybe this is fixable given the good description in #7.

anitap0322’s picture

Title: PDO fatal when using drush genu 50 » PDO fatal
Version: 7.x-1.x-dev » 7.x-1.0
Component: devel_generate » devel
Priority: Normal » Critical

I am receiving the same error. Not sure looking at the above posts if I know exactly the solution.

Here is the errors I see:

Notice: Undefined property: stdClass::$uri in file_save() (line 575 of /home/theclub/public_html/990clubv1/includes/file.inc).
Warning: Cannot modify header information - headers already sent by (output started at /home/theclub/public_html/990clubv1/includes/common.inc:2561) in drupal_send_headers() (line 1040 of /home/theclub/public_html/990clubv1/includes/bootstrap.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} (filesize, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1318935723 ) in drupal_write_record() (line 6776 of /home/theclub/public_html/990clubv1/includes/common.inc).

greggles’s picture

I believe this is caused by permission issues on the directories.

Be sure whatever user is running the script has the right permissions on the files directory and all subdirectories. If you are running something as drush then it runs as the command line user so that user needs to have read/write on the files directory (possibly via unix groups management).

danielnolde’s picture

This behaviour is almost certainly caused by a little bug / omission in devel.module's filefield content generation plugin, which currently doesn't handle directory preparation/creation correctly.

Details and SOLUTION (with patch) see: http://drupal.org/node/1349288

greggles’s picture

Status: Active » Closed (duplicate)
aslamise’s picture

Had same issue when uploading image after removing file from server.
Solved by going to admin/content/media and removing old media content from there.