diff --git a/modules/content_migrate/modules/content_migrate.filefield.inc b/modules/content_migrate/modules/content_migrate.filefield.inc
index 0c2c000..e00be46 100644
--- a/modules/content_migrate/modules/content_migrate.filefield.inc
+++ b/modules/content_migrate/modules/content_migrate.filefield.inc
@@ -7,7 +7,7 @@
 
 /**
  * Implements hook_content_migrate_field_alter().
- * 
+ *
  * Use this to tweak the conversion of field settings
  * from the D6 style to the D7 style for specific
  * situations not handled by basic conversion,
@@ -40,7 +40,7 @@ function content_migrate_filefield_field_alter(&$field_value, $instance_value) {
 
 /**
  * Implements hook_content_migrate_instance_alter().
- * 
+ *
  * Use this to tweak the conversion of instance or widget settings
  * from the D6 style to the D7 style for specific
  * situations not handled by basic conversion, as when
@@ -95,7 +95,7 @@ function content_migrate_filefield_instance_alter(&$instance_value, $field_value
 
   // Translate the original imagefield and fielfield widgets.
   switch ($instance_value['widget']['module']) {
-  
+
     case 'imagefield':
       // Module names and types changed.
       $instance_value['widget']['module'] = 'image';
@@ -128,7 +128,7 @@ function content_migrate_filefield_instance_alter(&$instance_value, $field_value
       unset($instance_value['widget']['settings']['alt']);
       unset($instance_value['widget']['settings']['max_filesize_per_node']);
       unset($instance_value['widget']['settings']['title_type']);
-               
+
       // default_image is now a field setting.
       unset($instance_value['widget']['settings']['default_image']);
       break;
@@ -211,25 +211,38 @@ function content_migrate_filefield_data_record_alter(&$record, $field, $instance
       $file->uri = file_stream_wrapper_uri_normalize($file->uri);
       unset($file->filepath);
 
-      // Insert into the file_managed table.
-      // Each fid should only be stored once in file_managed.
-      db_merge('file_managed')
-        ->key(array(
-          'fid' => $file->fid,
-        ))
-        ->fields(array(
-          'uid' => $file->uid,
-          'filename' => $file->filename,
-          'uri' => $file->uri,
-          'filemime' => $file->filemime,
-          'filesize' => $file->filesize,
-          'status' => $file->status,
-          'timestamp' => $file->timestamp,
-        ))
-        ->execute();
+      //Check for existing FID or URI, the unique keys.
+      //Each fid/uri can only be stored once in file_managed.
+      $fid_or_uid = db_or()->condition('fid', $file->fid)->condition('uri', $file->uri);
+      $existing = db_select('file_managed', 'f')
+              ->fields('f', array('fid', 'uri'))
+              ->condition($fid_or_uid)
+              ->execute()->fetchAssoc();
+
+      if (empty($existing)) {
+        //File or URI doesn't exist, save it.
+        drupal_write_record('file_managed', $file);
+      }
+      else {
+        //FID/URI exists, load it instead
+        drupal_set_message(t('Filefield URI/FID duplication found. Check system log messages for details.'), 'error', FALSE);
+
+        if ($existing['uri'] == $file->uri) {
+          //If URI is the same, post a warning.
+          watchdog('content_migrate', 'Filefield URI duplication found for nid: !nid, field:!field. Old fid:!ofid. New fid:!nfid. Uri:!uri.',
+            array('!nid' => $nid, '!field' => $field['field_name'], '!ofid' => $file->fid, '!nfid' => $existing['fid'], '!uri' => $file->uri), WATCHDOG_WARNING);
+        }
+        else {
+          //If URI is the different, post an error. Wrong file may be used.
+          watchdog('content_migrate', 'Filefield FID duplication found for nid: !nid, field:!field. Old fid:!ofid. Old uri:!ouri. New fid:!nfid. New uri:!nuri. File data may be incorrect.',
+            array('!nid' => $nid, '!field' => $field['field_name'], '!ofid' => $file->fid, '!nfid' => $existing['fid'], '!ouri' => $file->uri, '!nuri' => $existing['uri']), WATCHDOG_ERROR);
+        }
+
+        $file = file_load($existing['fid']);
+      }
 
       // Add the usage entry for the file.
       file_usage_add($file, 'file', 'node', $nid);
       break;
   }
-}
\ No newline at end of file
+}
