How can I avoid  the "The file x.jpg is in use and cannot be deleted." warning I get when I try to delete a media file? On the page admin/content/media I'm trying to remove a file, and I get the following warning:


  The file x.jpg is in use and cannot be deleted.


We've been struggling with this issue for some time now, and it looked like the root of the problem was related to the list of revisions in the node the file was in. Deleting the revisions enabled us to delete the file.

Has anybody experienced this issue? Is there a way to fix it?  

It's not a great idea for us to have to remove all previous revisions of a node in order to just delete some duplicated files from the media library.
To be honest this is the behaviour that should be expected of the field/revision system.

If you have an image file that is attached to a node revision, Drupal (rightly) makes sure that another process in the system cannot delete it. If this wasn't done you'd end up with incomplete/erroneous node revisions.

The only options you've got (in terms of the UI anyway) are either deleting the revisions (which you already know about), or removing the reference to the file from the revision(s) in question.

If you're feeling brave you could dive straight into these tables and make the changes manually:


node
node_revision
field_data_field_FIELDNAME
field_revision_field_FIELDNAME


But I strongly advise you only go down that route if you really, really know what you're doing, and have a good backup system in place :)