删除 OS X 上的 CoreData 存储?
我正在 Mac OS X 应用程序中使用 CoreData。更改实体后,我收到以下错误:
用于打开持久存储的托管对象模型版本与用于创建持久存储的托管对象模型版本不兼容。
我为此问题找到的所有答案都建议在应用程序中实施版本控制/迁移,但我对保存数据不感兴趣。难道没有一个不太复杂的解决方案吗?比如删除库存文件之类的?如果是,该文件位于哪里?
谢谢。
I'm playing around with CoreData in a Mac OS X application. After changing an entity i got the following error:
The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store.
All answers i've found for this issue suggest implementing versioning/migration into the app, but I'm not interested in saving my data. Isn't there a less complicated solution for that? Like deleting the stock file or something like that? And if yes, where is this file located?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您不想要这些数据,那么可以,您只需删除旧文件并创建一个新文件即可。如果您的数据基于文档,则应删除文档本身。如果您对整个应用程序使用单个商店(不是基于文档),那么您应该查看创建商店对象的代码以查找位置。该模板将创建代码放置在应用程序委托中,存储的默认位置位于
${HOME}/Library/Application Support/${APP_NAME}/
中。If you don't want the data, then yes, you can simply delete the old file and create a new one. If your data is document based, then the document itself should be deleted. If you use a single store for the whole application (not document based), then you should look in the code that creates the store object to find the location. The template places the creation code in the application delegate, and the default location for the store is in
${HOME}/Library/Application Support/${APP_NAME}/
.在 OS X 10.7 Lion 上,当应用程序被沙盒化时,它存储在:
On OS X 10.7 Lion when the app is sandboxed, it is stored in:
我发现对于 Mac OS X 10.8 / Xcode 4.6,数据存储在 下的派生数据文件夹中。
删除此数据的最简单方法是转到组织器,选择项目选项卡,然后单击派生的“删除...”按钮数据。
I found that for Mac OS X 10.8 / Xcode 4.6 the data is stored in the derived data folder of under
The easiest way to delete this data is to go to the organiser, select project tab and click "Delete..." button by derived data.
或者,对于 OSX,使用 Nsfilemanager 通过使用
lazy var permanentStoreCoordinator: NSPersistentStoreCoordinator{...}
中定义的 url 来删除文件。在此 var permanentStoreCoordinator 中,将定义一个 url,该 url 被设计为由 persistenceStoreCoordinator 使用。您只需使用那里定义的 url 即可删除旧商店。插入以下代码。运行项目,文件将被删除。 然后删除代码以允许对象再次存储,而不是每次都删除数据。
这是我在
lazy var permanentStoreCoordinator: NSPercientStoreCoordinator
中找到的内容,这是我直接放在它下面的内容。
然后我点击运行。它运行一次然后我删除我刚刚编写的代码,这样数据就不会每次都被删除
Alternatively, For OSX, use the Nsfilemanager to delete the file by using the url defined in the
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator{...}
In this var persistentStoreCoordinator a url will be defined that is designed to be used by the persistentStoreCoordinator. You can just use the url defined there to delete the old store. Insert the below code. Run the project and the file will be deleted. Then delete the code to allow objects to be stored again and not delete the data every time.
here is what I found in the
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator
here is what i put immediately underneath it.
then i clicked run. It ran once then i delete the code i just made so that the data would not be deleted every time
在 macOS Big Sur (11.4) 中,可以在以下位置找到本地 NSPersistentCloudKitContainer 核心数据存储:
In macOS Big Sur (11.4), local NSPersistentCloudKitContainer Core Data storage can be found at:
在 Mac OS X 10.11.4 上,使用 Xcode 7.3 清理解决了我的问题:
Product
>Clean
或 Shift⌘KOn Mac OS X 10.11.4 with Xcode 7.3 cleaning the fixed the problem for me:
Product
>Clean
or Shift⌘K尝试在您以前未使用过的其他设备的模拟器中运行该应用,看看它是否对您有帮助(即 iPhone SE 而不是 iPhone 7)。如果是这样,那么删除损坏的文件夹应该会有所帮助。 打开终端并运行以下命令:
删除可能损坏的模拟器数据、
删除应用程序的数据。
希望有帮助!
Try to run the app in a simulator of another device that you haven't used before and see if it helps you (i.e. iPhone SE instead of iPhone 7). If it does, then removing the corrupted folders should help. Open Terminal and run the following commands:
to remove the simulators' data that might be corrupted,
to remove your app's data.
Hope that helps!