gpt4 book ai didi

ios - 核心数据迁移 : 'Can' t merge models with two different entities. ..'

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:30 25 4
gpt4 key购买 nike

我向 Core Data 模型添加了新版本。我向一个实体添加了新属性 (Seriese)

但它引发异常

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't merge models with two different entities named 'Seriese'' 

我使用以下代码:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationPrivateDocumentsDirectory] stringByAppendingPathComponent: @"CoreDataTutorialPart4.sqlite"]];

NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];


if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {

NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

return persistentStoreCoordinator;
}

有什么解决这个错误的建议吗?我不想丢失保存的数据

最佳答案

问题很可能来自加载托管对象模型的方式。默认方法是合并 bundle 中的模型,但是在这种情况下,您实际上有两个具有相同实体(v1 和 v2)的模型……这里解释得很好……Migration Issues

关于ios - 核心数据迁移 : 'Can' t merge models with two different entities. ..',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6094982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com