By f.albert on
Hi,
I'm currently developping a module which creates 1 node per file uploaded. I've implemented the file_insert() hook and it's working ; I also want to have 1 node per file for my older files so I've implemented the cron() hook. But it doesn't work.
After calling 10 times node_save() in my loop, I get this error :
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] => 1328708558 )
in drupal_write_record() (line 6888 of D:\FALBERT\Outils\xampp\htdocs\drupal\includes\common.inc).
The first 10 iterations goes without problem, nodes are created, it's bugging for the 11th. I deleted some files to ensure that the problem is not related to the file.
And once I get the bug, I can't run the script again, I get the error immediately.
Any help would be greatly appreciated.
Thanks in advance
Comments
You might post your code so
You might post your code so others can see whats it's doing.
However you are saving your
However you are saving your file, you aren't passing the URI to it. The URI is a unique key, so after one row was entered with an empty key, the next one caused the error you saw. Can't say more without code.
Contact me to contract me for D7 -> D10/11 migrations.
Wrong table
Thanks for your replies.
In fact I was looking in the wrong table for the files uploaded. For some reasons I have a "files" table but it's not where Drupal stores the information about uploaded files (it's actually in the "file_managed" table). That's why I don't have an URI for some files.
Thanks again.
See: #1163740: PDOException:
See: #1163740: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed}