一、 Lightweight Migration

i. 适合场景

Simple addition of a new attribute

Removal of an attribute

A non-optional attribute becoming optional

An optional attribute becoming non-optional, and defining a default value

Renaming an entity or property

ii. 如何做

1. 设置Persistent Store:

NSDictionary *persistentStoreOptions = @{ NSMigratePersistentStoresAutomaticallyOption : @YES,

NSInferMappingModelAutomaticallyOption : @YES };

persistentStore = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:persistentStoreOptions error:&addStoreError];

2. 给database.xcdatamodel添加版本

select database.xcdatamodel -> Editor -> Add Model Version,然后设置当前数据库对应的data model文件是哪个便好。

3.这样便完成了。so easy, so simple。而此种迁移方式,占据大部分的数据库数据迁移的应用场景。

二、Multiple Passes

这项技术,我当前还未遇到需要使用它的场景,所以没有花时间研究。至于如何处理,可以参照一篇很不错的博客, http://www.cnblogs.com/liyufeng2013/p/3782351.html

Apple official doc: https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmMappingOverview.html#//apple_ref/doc/uid/TP40004399-CH5-SW1

Core Data数据库迁移的更多相关文章

  1. Core Data 版本号迁移经验总结

    大家在学习和使用Core Data过程中,第一次进行版本号迁移的经历一定是记忆犹新,至少我是这种,XD.弄的不好,就会搞出一些因为迁移过程中数据模型出错导致的Crash.这里总结了一下Core Dat ...

  2. 工程日记之HelloSlide(3):如何使用Core Data数据库,以及和sqlite之间的对应关系

    Core Data 和 SQLite 是什么关系 core data是对sqlite的封装,因为sqlite是c语言的api,然而有人也需要obj-c的api,所以有了core data ,另外,co ...

  3. Entity Framework Core 之数据库迁移

    前言 最近打算用.NET Core写一份开源的简易CMS系统,来练练手 所以又去深入研究了一下Entity Framework Core 发现其实有些细节园子里还是很少讲到. 特意整理了几个细节. 正 ...

  4. 二、core abp 数据库迁移

    一.数据库迁移-ABP(库) 1.配置链接数据库:  贴以下代码: { "ConnectionStrings": { "Default": "Serv ...

  5. 谈谈EF Core实现数据库迁移

    作为程序员,在日常开发中,记忆犹新的莫过于写代码,升级程序.升级程序包含两部分:一是,对服务程序更新:二是,对数据库结构更新.本篇博文主要介绍数据库结构更新,在对数据库升级时,不知道园友们是否有如下经 ...

  6. 添加Entity Framework Core,数据库迁移

    1.建立Entity 建立IEntity的接口 建立实现IEntity接口的抽象类Entity 建立类继承抽象类Entity 2. 数据库放到infrastructure的项目中 3.注册和配置这个d ...

  7. .Net Core建站(2):EF Core+CodeFirst数据库迁移

    上一篇的话,说了下怎么使用EF7 实现 CodeFirst去生成数据库, 其实还有好多问题的,这次一点一点的解决吧,都挺简单,不过零零散散的,, 1.读取配置文件,获得链接字符串 2.使用数据库进行增 ...

  8. ASP.NET CORE系列【六】Entity Framework Core 之数据库迁移

    前言 最近打算用.NET Core写一份简单的后台系统,来练练手 然后又用到了Entity Framework Core 发现园子里有些文章讲得不是那么细节,对于新手小白来说,可能会有点懵. 特意整理 ...

  9. iOS Core Data 数据库的加密(待研究)

    https://github.com/project-imas/encrypted-core-data 使用起来很方便,底层还是使用了SQLCipher,有时间要研究一下! 数据库的密码不能用固定字符 ...

随机推荐

  1. mysql 排重查询

    GROUP BY 语句可以实现某一列的去重查询. 直接上语句: select io_dev_id from io_info where (TID=1 AND host_name='yang1') GR ...

  2. How to setup and process Intercompany accounting [AX2012]

    In this post, I will take you through a very simple functionality called  the intercompany accountin ...

  3. 一幅图证明chrome的由来和目的

  4. activiti

    http://activiti.org/designer/archived/  eclipse plugin

  5. shell-IF判断

    #!/bin/bash echo "-----------------strat---------------" read -p "Enter a number:&quo ...

  6. 如何从官网下载springframework和document

    spring官网 http://spring.io/ --->spring project--->点击github图标 --->artifactory --->进入到了http ...

  7. golang处理错误的艺术

    golang中关键API的调用都会在最后返回err(golang多值返回). 调用者可以选择处理, 或者不处理该err, 或原装返回给上一层的调用者. golang中的err是error类型, typ ...

  8. NFC framework

    NFC framework introduce 1 NFC简介 对于NFC,是google在android4.0上推出来的,简单介绍下.近场通讯(NFC)是一系列短距离无线技术,一般需要4cm或者更短 ...

  9. mysql开启日志

    在 centos 5 下,  在 mysld 下面,添加一行 log=/var/log/mysql.log 然后执行如下命令 touch /var/log/mysql.logchmod 777 /va ...

  10. iOS学习之C语言函数

    一.函数的定义 返回值类型 函数名(参数类型 参数名, ...) { 功能语句; return 返回值; } 按照返回值和参数划分: 第一种: 无返回值 无参 void sayHello() { pr ...