[SwiftUI] multiple NSPersistentContainer generate error: A fetch request must have an entity.

I work with CoreData and need to backup/sync entire database to cloud server. The main CoreData is work well to show data in each view.

But when I backup sqlite file to cloud server, then download sqlite file to another local location in iPhone, then I load NSPersistentContainer for this sqlite database file. Xcode shows "error: A fetch request must have an entity."

Note: I'm sure that one NSPersistentContainer is load one sqlite file, two NSPersistentContainer is not point to the same file. Note2: This concept is work well in previous version of swift, but now I try to implement this concept with SwiftUI.

Please suggest me for some ideas and/or solutions.

This is an example code that generate error ...

Why I cannot loadPersistentStores with 2 sqlite files ?

import CoreData
struct PersistenceController {
    static let shared = PersistenceController()
    let container: NSPersistentContainer
    let container2: NSPersistentContainer
    func urlApplicationSupportDirectory() -> URL {
        let paths = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
        let documentsDirectory = paths[0]
        return documentsDirectory
    }

	func sqliteURL() -> URL {
		let url = urlApplicationSupportDirectory().appendingPathComponent("MM1.SQLite")
		return url
	}
	func sqliteURL2() -> URL {
		let url = urlApplicationSupportDirectory().appendingPathComponent("MM2.SQLite")
		return url
	}

	init(inMemory: Bool = false) {
        container = NSPersistentContainer(name: "testCoreData")
		container2 = NSPersistentContainer(name: "testCoreData")
        if inMemory {
            container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
        }
		let url = sqliteURL()
		print(url.absoluteString)
		let description = NSPersistentStoreDescription(url: url)
		description.shouldMigrateStoreAutomatically = true
		description.shouldInferMappingModelAutomatically = true
		container.persistentStoreDescriptions = [description]
        container.viewContext.automaticallyMergesChangesFromParent = true
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })

		let url2 = sqliteURL2()
		print(url2.absoluteString)
		let description2 = NSPersistentStoreDescription(url: url2)
		description2.shouldMigrateStoreAutomatically = true
		description2.shouldInferMappingModelAutomatically = true
		container2.persistentStoreDescriptions = [description2]
		container2.viewContext.automaticallyMergesChangesFromParent = true
		container2.loadPersistentStores(completionHandler: { (storeDescription, error) in
			if let error = error as NSError? {
				fatalError("Unresolved error \(error), \(error.userInfo)")
			}
		})
	}
}
[SwiftUI] multiple NSPersistentContainer generate error: A fetch request must have an entity.
 
 
Q