diff --git a/modules/Migration/schema/660_to_700.php b/modules/Migration/schema/660_to_700.php
index bd78c8a2cabace32fd385ad167c6fa7f7137fec7..ac2867996724bad78f4e26f59884816d2a1f0c35 100644
--- a/modules/Migration/schema/660_to_700.php
+++ b/modules/Migration/schema/660_to_700.php
@@ -2203,6 +2203,9 @@ if(defined('VTIGER_UPGRADE')) {
 					$referenceTable = $baseTableName;
 					$referenceColumn = $baseTableIndex;
 
+                    if($baseTableName == 'vtiger_activity'){
+                        array_push($moduleName, "Emails");
+                    }
 					if ($tableName == 'vtiger_producttaxrel' || $tableName == 'vtiger_inventoryproductrel') {
 						$referenceTable = 'vtiger_crmentity';
 						$referenceColumn = 'crmid';
@@ -2215,7 +2218,7 @@ if(defined('VTIGER_UPGRADE')) {
 					}
 				}
 			}
-			$db->pquery("DELETE FROM $baseTableName WHERE $baseTableIndex NOT IN (SELECT crmid FROM vtiger_crmentity WHERE setype=?)", array($moduleName));
+			$db->pquery("DELETE FROM $baseTableName WHERE $baseTableIndex NOT IN (SELECT crmid FROM vtiger_crmentity WHERE setype in ". generateQuestionMarks($moduleName).")", array($moduleName));
 		}
 	}