diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
index 811d82d7437e570883f20328e84c55264619d998..230690d35c35e466b0cd939775bbb1c89f92a2d3 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -39,9 +39,10 @@ class Upgrade {
 
 		if ($row = $this->legacy->get($path)) {
 			$data = $this->getNewData($row);
-			$this->insert($data);
-
-			$this->upgradeChilds($data['id'], $mode);
+			if ($data) {
+				$this->insert($data);
+				$this->upgradeChilds($data['id'], $mode);
+			}
 		}
 	}
 
@@ -53,9 +54,11 @@ class Upgrade {
 		foreach ($children as $child) {
 			$childData = $this->getNewData($child);
 			\OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $child['path']);
-			$this->insert($childData);
-			if ($mode == Scanner::SCAN_RECURSIVE) {
-				$this->upgradeChilds($child['id']);
+			if ($childData) {
+				$this->insert($childData);
+				if ($mode == Scanner::SCAN_RECURSIVE) {
+					$this->upgradeChilds($child['id']);
+				}
 			}
 		}
 	}
@@ -95,20 +98,25 @@ class Upgrade {
 	 */
 	function getNewData($data) {
 		$newData = $data;
-		list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($data['path']);
 		/**
 		 * @var \OC\Files\Storage\Storage $storage
 		 * @var string $internalPath;
 		 */
-		$newData['path_hash'] = md5($internalPath);
-		$newData['path'] = $internalPath;
-		$newData['storage'] = $this->getNumericId($storage);
-		$newData['parent'] = ($internalPath === '') ? -1 : $data['parent'];
-		$newData['permissions'] = ($data['writable']) ? \OCP\PERMISSION_ALL : \OCP\PERMISSION_READ;
-		$newData['storage_object'] = $storage;
-		$newData['mimetype'] = $this->getMimetypeId($newData['mimetype'], $storage);
-		$newData['mimepart'] = $this->getMimetypeId($newData['mimepart'], $storage);
-		return $newData;
+		list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($data['path']);
+		if ($storage) {
+			$newData['path_hash'] = md5($internalPath);
+			$newData['path'] = $internalPath;
+			$newData['storage'] = $this->getNumericId($storage);
+			$newData['parent'] = ($internalPath === '') ? -1 : $data['parent'];
+			$newData['permissions'] = ($data['writable']) ? \OCP\PERMISSION_ALL : \OCP\PERMISSION_READ;
+			$newData['storage_object'] = $storage;
+			$newData['mimetype'] = $this->getMimetypeId($newData['mimetype'], $storage);
+			$newData['mimepart'] = $this->getMimetypeId($newData['mimepart'], $storage);
+			return $newData;
+		} else {
+			\OC_Log::write('core', 'Unable to migrate data from old cache for '.$data['path'].' because the storage was not found', \OC_Log::ERROR);
+			return false;
+		}
 	}
 
 	/**