我有一个使用旧版 realm(v0.85.1) 的实时应用程序,我正在开发一个使用 4.2.0 版 realm 并且也有模式更改的新版本。架构更改只是将单个列添加到一个表中。对于迁移,我有这个类。
public class ImRealmMigration implements RealmMigration{
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
if(oldVersion == 0){
schema.get("Layout")
.addField("orientation", String.class, FieldAttribute.REQUIRED);
oldVersion++;
}
}
}
在应用程序类中我有这个
Realm.init(this);
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name("default.realm")
.schemaVersion(1)
.migration(new ImRealmMigration())
.build();
Realm.setDefaultConfiguration(realmConfiguration); // Make this Realm the default
Realm realm = Realm.getInstance(realmConfiguration);
当我运行该应用程序时,它一直运行到最后一行,它抛出 RealmMigrationNeededException 并继续列出模式中的所有主键,表明它们已成为可选的。有谁知道为什么会发生这种情况以及我能做些什么来解决它?这是堆栈跟踪:
FATAL EXCEPTION: main
java.lang.RuntimeException:
Unable to start activity io.realm.exceptions.RealmMigrationNeededException:
Migration is required due to the following errors:
- Property 'Book.privateId' has been made optional.
- Property 'BookType.bookTypeId' has been made optional.
- Property 'Cart.id' has been made optional.
- Property 'ClipArt.url' has been made optional.
- Property 'Contact.userId' has been made optional.
- Property 'CreditAccount.id' has been made optional.
- Property 'Layout.layoutId' has been made optional.
- Property 'LayoutClipArtItem.layoutItemId' has been made optional.
- Property 'LayoutItem.itemId' has been made optional.
- Property 'LayoutPhotoItem.layoutItemId' has been made optional.
- Property 'LayoutShapeItem.layoutItemId' has been made optional.
- Property 'LayoutTextItem.layoutItemId' has been made optional.
- Property 'OrderSession.id' has been made optional.
- Property 'PagePhoto.pagePhotoId' has been made optional.
- Property 'Photo.privateId' has been made optional.
- Property 'PhotoOrigin.identifier' has been made optional.
- Property 'PrintPack.privateId' has been made optional.
- Property 'PrintType.printTypeId' has been made optional.
- Property 'Product.productId' has been made optional.
- Property 'ProductFamilyMarketing.productFamilyType' has been made optional.
- Property 'Region.rid' has been made optional.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.ActivityThread.access$1000(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1735)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors:
- Property 'Book.privateId' has been made optional.
- Property 'BookType.bookTypeId' has been made optional.
- Property 'Cart.id' has been made optional.
- Property 'ClipArt.url' has been made optional.
- Property 'Contact.userId' has been made optional.
- Property 'CreditAccount.id' has been made optional.
- Property 'Layout.layoutId' has been made optional.
- Property 'LayoutClipArtItem.layoutItemId' has been made optional.
- Property 'LayoutItem.itemId' has been made optional.
- Property 'LayoutPhotoItem.layoutItemId' has been made optional.
- Property 'LayoutShapeItem.layoutItemId' has been made optional.
- Property 'LayoutTextItem.layoutItemId' has been made optional.
- Property 'OrderSession.id' has been made optional.
- Property 'PagePhoto.pagePhotoId' has been made optional.
- Property 'Photo.privateId' has been made optional.
- Property 'PhotoOrigin.identifier' has been made optional.
- Property 'PrintPack.privateId' has been made optional.
- Property 'PrintType.printTypeId' has been made optional.
- Property 'Product.productId' has been made optional.
- Property 'ProductFamilyMarketing.productFamilyType' has been made optional.
- Property 'Region.rid' has been made optional.
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method)
at io.realm.internal.OsSharedRealm.<init>(OsSharedRealm.java:172)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:219)
at io.realm.BaseRealm.<init>(BaseRealm.java:124)
at io.realm.BaseRealm.<init>(BaseRealm.java:93)
at io.realm.Realm.<init>(Realm.java:153)
at io.realm.Realm.createInstance(Realm.java:424)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:342)
at io
最佳答案
0.89.0
Breaking changes
@PrimaryKey field value can now be null for String, Byte, Short, Integer, and Long types. Older Realms should be migrated, using RealmObjectSchema.setNullable(), or by adding the @Required annotation (#2515).
请参阅版本 0.89.0 的更改日志
您可以通过在 @PrimaryKey 字段上添加 @Required 轻松绕过此问题。
关于android - RealmMigrationNeededException 同时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47535723/
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
在previousquestion中我想出了如何在多个服务器上启动经过密码验证的sshsession来运行单个命令。现在我需要能够执行“sudo”命令。问题是,net-ssh-multi没有分配sudo需要运行的伪终端(pty),导致以下错误:[127.0.0.1:stderr]sudo:sorry,youmusthaveattytorunsudo根据documentation,可以通过调用channel对象的方法来分配伪终端,但是,以下代码不起作用:它会生成上面的“notty”错误:require'net/ssh'require'net/ssh/multi'Net::SSH::Mul
是否可以同时传递GET和POST参数?uri=URI.parse("http://www.example.com/post.php?a=1&b=2")req=Net::HTTP::Post.new(uri.path,{'Referer'=>"http://www.example.com/referer",'User-Agent'=>"Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1)",'Cookie'=>$cookie})req.set_form_data({'foo'=>'bar','bar'=>'foo'})http=Net::HTTP.ne
我想制作一个gem,当其他人尝试将它与MRI一起使用时,它将使用C代码,而当他们从JRuby中使用它时,它将使用Java代码。nokogiri和pumagems就是这样做的,我看过他们的代码,但没有看到他们是如何实现的。 最佳答案 这是通过使用rvm(或其他类似工具在rubies之间切换)和rake-compiler为您针对的不同平台交叉编译gem来完成的。.gemspec文件必须指定每个平台所需的文件;这是通过检查gem正在编译的平台来完成的:Gem::Specification.newdo|gem|#...ifRUBY_PLAT
通过rvm升级到Ruby2.3的最佳方法是什么,同时保持所有gem安装在以前的版本上(例如json、nokogiri、等等)? 最佳答案 编辑这个问题在这里有答案:RVM:Howtousegemsfromadifferentruby?$rvmgemsetcopy$oldversion2.3.0##Assignorreplace$oldversionwitholdversionname原创在安装Ruby2.3之前,使用gemlist获取已安装的gem及其版本的列表。然后,在安装Ruby2.3之后,使用rvm将2.3设置为新的默认值:$
运行有问题或需要源码请点赞关注收藏后评论区留言一、利用ContentResolver读写联系人在实际开发中,普通App很少会开放数据接口给其他应用访问。内容组件能够派上用场的情况往往是App想要访问系统应用的通讯数据,比如查看联系人,短信,通话记录等等,以及对这些通讯数据及逆行增删改查。首先要给AndroidMaifest.xml中添加响应的权限配置 下面是往手机通讯录添加联系人信息的例子效果如下分成三个步骤先查出联系人的基本信息,然后查询联系人号码,再查询联系人邮箱代码 ContactAddActivity类packagecom.example.chapter07;importandroid
1.前言 在10.0的系统rom定制化开发中,在系统中有多个launcher的时候,会在开机进入launcher的时候弹窗launcher列表,让用户选择进入哪个launcher,这样显得特别的不方便所以产品开发中,要求用RoleManager的相关api来设置默认Launcher,但是在设置完默认Launcher以后,在安装一款Launcher的时候,默认Launcher就会失效,在系统设置的默认应用中Launcher选项就为空,点击home键的时候会弹出默认Launcher列表,让选择进入哪个默认Launcher.所以需要从安装Launcher的流程来分析相关的设置。来解决问题设置默认La
我编写了一个内容管理系统,它使用服务器端正则表达式在将页面响应发送到客户端浏览器之前转义页面响应中的&符号。正则表达式注意已经转义或属于HTML实体一部分的&符号。例如,以下内容:a&b,c&d,©2009getschangedtothis:a&b,c&d,©2009(Onlythefirst&ismodified.)Hereistheregularexpression,whichwastakenandmodifiedfromaRailshelper:html.gsub(/&(?!([a-zA-Z][a-zA-Z0-9]*|(#\d+));)
如何同时替换2个字符串?例如,假设我有这样的字符串:str1="AAAABBBBCCCCDDDD"我想用“CCCC”替换每个“AAAA”,用“AAAA”替换每个“CCCC”,但如果我这样做了:str1.gsub("AAAA","CCCC")#CCCCBBBBCCCCDDDDstr1.gsub("CCCC","AAAA")#AAAABBBBAAAADDDD我希望str1成为“CCCCBBBBAAAADDDD” 最佳答案 一般答案:使用正则表达式匹配AAAA和CCCC,然后分别用CCCC和AAAA替换每个匹配项。编辑以消除混淆str1.
我试过按照这个answer让gem工作,但它不会。我设置了我的项目,这样各个项目都有自己的gem,而不是生活在全局空间中的所有主题gem,然后我使用binstubs来允许我做bin/rails.因此,每个项目的所有gem都安装到.bundle/gems/。总是给我带来最棘手问题的是posgresql。让我们完成这些步骤。所以我跑:bundle它爆炸说:Gem::Installer::ExtensionBuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Ver