How to force migrations to not copy files I have a migration with an image field and the files already exist on the server where I want them.

There is a file, some_file.jpg that already exists at sites/default/files/some_file.jpg but when I run the migration, it tries to copy the file from sites/default/files/some_file.jpg to sites/default/files/node_type/some_file.jpg and then also creates another file entity for it.  I just want it to re-use the file and file entity that already exist for it.  The destination field type is an image field.

I have this on the field mapping for the file field:

$this-&gt;addFieldMapping('field_upload_image', 'field_res_upload_photo');
$this-&gt;addFieldMapping('field_upload_image:preserve_files')
     -&gt;defaultValue(TRUE);
$this-&gt;addFieldMapping('field_upload_image:file_replace')
     -&gt;defaultValue(MigrateFile::FILE_EXISTS_REUSE);
Well if thats not working do a scan for the file on the destination location to set or unset the field value (so it's not updated on save). You can do this in the prepare function of your migration class. See the commonly implemented migration methods page for example implementations.

Also have you tried setting the preserved_files key:

    $this-&gt;addFieldMapping('field_images:preserve_files')
  -&gt;defaultValue(TRUE);


I haven't done any file migrations myself lately, but I stumbled across that in this thread: https://www.drupal.org/node/1886404  it looks like you got the field ordering correct (well from the issue the source field primary and sub-field ordering now no longer matters).