Is there a way i can make file_managed URI changes in the database?

I the database i have a list of files and there is append a _1 or _2 to the URI file name.i wanted to clean these up and remove the _number so there will be only one file but when i change it i get an error unable to write row duplicate entry for uri key.


Doing this directly in the database can be messy given the way Drupal abstracts its managed files. It is usually better to try and find a solution that works with the Drupal file API directly so you're not forgetting some entry somewhere and leaving extra cruft in your database. You could roll your own solution using the file API and file_delete() but I would suggest that you're better off doing this using an interface like IMCE and combining that with a solution like this module:


which would resolve this problem for you going forwards:

The problem with drupal is if you have a file called "mydoc.doc" upload it to a node, then make changes to "mydoc.doc" and upload the newer version, the newer version will be renamed to "mydoc_0.doc" because at the time of upload the old file was blocking the desired path name.

This module solves that problem by swapping the names of the older and newer file so that the newly uploaded file will retain its original name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.