Avoid duplicate files on migrate update I am creating file entities with migrate using drush. Image files are being copied down from a remote server.
I tried 

$this-&gt;addFieldMapping('file_replace')-&gt;defaultValue('FILE_EXISTS_REPLACE');
$this-&gt;addFieldMapping('preserve_files')-&gt;defaultValue(TRUE);


If I run the migration with --update it duplicates the files, not replacing existing ones.

drush mi DAProductImages --limit="10 items" --update


When I run this first time it creates the files. Second time it adds _0 to the filenames and duplicates the files. If I rollback after first migration the files are being removed. When rolling back after the second migration only files of last batch get removed. I also tried with:

$this-&gt;addFieldMapping('preserve_files')-&gt;defaultValue(FALSE);


How can I make it so that I will not end up with duplicates? I have about 30000 images so I cannot afford that.
This solved it for me.  

The documentation at this link was missing a mention that you need to use the class prefix - I just submitted an update to the Drupal Docs to make it more clear:

$this-&gt;addFieldMapping('preserve_files')
  -&gt;defaultValue(1);

$this-&gt;addFieldMapping('file_replace')
  -&gt;defaultValue(MigrateFile::FILE_EXISTS_REUSE);