预填充数据库。现在我想添加更多的数据,而不会弄乱预先存在的数据 [英] Pre-populated database. Now I want to add more data without messing the pre-existing data

查看:113
本文介绍了预填充数据库。现在我想添加更多的数据,而不会弄乱预先存在的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已设置和应用程序已预填充数据,将数据库复制到项目的存储。使用CoreDataBooks示例方法:
以任何方式预填充核心数据?

I have set up and app which has pre-populated data that copies the database to the project's store. Using the 'CoreDataBooks example' method: Any way to pre populate core data?

对于应用程序升级,我想向数据库添加更多数据,但我不想更改现有数据库,因为新用户数据存储在哪里?

For application upgrades, I want to add more data to the database but I don't want to change the existing database since new user data is stored there?

这是什么最好的方法?

What's the best way to do this?

我想我会创建一个新的版本管理对象模型(我不知道如果你可以添加一个新的MOM版本,如果模式中没有什么实际上改变) ,对于新版本,请阅读当前运行的MOM版本,将MOM迁移到最新版本,并手动添加自当前运行的MOM版本以来未添加的新记录。

I'm thinking I would create a new versioned managed object model (I'm not sure if you can add a new MOM version if nothing in the schema actually changes), for new versions, read the currently running MOM version, migrate the MOM to the latest version and manually add the new records in the code that have not been added since the currently running MOM version.

在代码中手动添加新记录似乎有点乏味。这是否正确,或者是否有更优雅的方式添加这些新数据?

It seems a bit tedious to manually add new records in the code. Does that sound right or is there a more elegant way to add this new data?

谢谢!

推荐答案

如果您更改管理对象模型本身,例如添加新实体或更改现有属性,则需要使用迁移来更新现有持久性存储。有关迁移的详细信息,请参阅Core Data文档。

If you change the managed object model itself e.g. add a new entity or change an existing attribute, then you need to use migration to update the existing persistent store. See the Core Data docs for details on migration.

如果您只是想添加新数据,则无需任何选择,只需手动。

If you just want to add new data, then you don't have any choice but to do so "manually."

记住,Core Data是一个对象图管理系统,而不是数据库。对象graph是相互关联的对象的web,所以向图中添加数据的唯一方法是创建新对象并设置它们的关系。这不是低效率,它只是它的工作方式。

Remember, Core Data is an object graph management system, not a database. An object "graph" is a "web" of interrelated objects so the only way to add data to the graph is to create new objects and set their relationships. It's not inefficient, it just the way it works.

这篇关于预填充数据库。现在我想添加更多的数据,而不会弄乱预先存在的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆