- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 Realm 从版本 0 迁移到版本 1。我的 POJO 如下:
@Parcel(implementations = {OrganizerRealmProxy.class},
value = Parcel.Serialization.BEAN,
analyze = {Organizer.class})
public class Organizer extends RealmObject {
@PrimaryKey
private long Id;
private String email;
private String displayName;
private Boolean self;
...
}
在我正在执行的迁移方法中:
RealmObjectSchema organizerSchema = schema.create("Organizer")
.addPrimaryKey("Id")
.addField("email", String.class)
.addField("displayName", String.class)
.addField("self", Boolean.class);
但是我遇到了异常:
Caused by: java.lang.IllegalArgumentException: Field name doesn't exist on object 'Organizer': Id
at io.realm.RealmObjectSchema.checkFieldExists(RealmObjectSchema.java:500)
at io.realm.RealmObjectSchema.addPrimaryKey(RealmObjectSchema.java:297)
at org.granitebaysda.bradapp.utils.RealmMigration.migrate(RealmMigration.java:20)
at io.realm.BaseRealm$2.onResult(BaseRealm.java:578)
at io.realm.RealmCache.invokeWithGlobalRefCount(RealmCache.java:242)
at io.realm.BaseRealm.migrateRealm(BaseRealm.java:565)
at io.realm.Realm.migrateRealm(Realm.java:1062)
at io.realm.Realm.migrateRealm(Realm.java:1051)
at io.realm.Realm.createInstance(Realm.java:231)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:114)
at io.realm.Realm.getInstance(Realm.java:191)
at org.granitebaysda.bradapp.MainActivity.onStart(MainActivity.java:114)at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5241)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515)
Realm 版本为0.87.2
使用 addField("id", String.class, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED)
而不是 addPrimaryKey
后,我开始遇到另一个异常:
io.realm.exceptions.RealmMigrationNeededException: Field 'id' does
support null values in the existing Realm file. Remove @Required or
@PrimaryKey from field 'id' or migrate using
io.realm.internal.Table.convertColumnToNotNullable()
我的完整迁移类代码如下所示:
public class RealmMigration implements io.realm.RealmMigration {
@Override
public void migrate(DynamicRealm dynamicRealm, long oldVersion, long newVersion) {
// DynamicRealm exposes an editable schema
RealmSchema schema = dynamicRealm.getSchema();
if (oldVersion == 0) {
RealmObjectSchema organizerSchema = schema.create("Organizer")
.addField("Id", long.class, FieldAttribute.PRIMARY_KEY)
.addField("email", String.class, FieldAttribute.INDEXED)
.addField("displayName", String.class)
.addField("self", Boolean.class);
RealmObjectSchema startSchema = schema.create("Start")
.addField("Id", long.class, FieldAttribute.PRIMARY_KEY)
.addField("dateTime", String.class)
.addField("timeZone", String.class)
.addField("date", String.class);
RealmObjectSchema endSchema = schema.create("End")
.addField("Id", long.class, FieldAttribute.PRIMARY_KEY)
.addField("dateTime", String.class)
.addField("timeZone", String.class)
.addField("date", String.class);
RealmObjectSchema eventCreatorSchema = schema.create("EventCreator")
.addField("email", String.class, FieldAttribute.PRIMARY_KEY)
.addField("displayName", String.class);
RealmObjectSchema AttendeeSchema = schema.create("Attendee")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY)
.addField("email", String.class)
.addField("displayName", String.class)
.addField("organizer", Boolean.class)
.addField("self", Boolean.class)
.addField("responseStatus", String.class);
RealmObjectSchema originalStartTimeSchema = schema.create("OriginalStartTime")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY)
.addField("dateTime", String.class);
RealmObjectSchema recurrenceSchema = schema.create("RecurrenceString")
.addField("Id", long.class, FieldAttribute.PRIMARY_KEY)
.addField("recurrence", String.class);
RealmObjectSchema EventRecurrenceDetailSchema = schema.create("EventRecurrenceDetail")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY)
.addField("freq", int.class)
.addField("byDay", int.class)
.addField("byDayNum", int.class)
.addField("until", String.class)
.addField("interval", String.class);
schema.create("Item")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED)
.addField("kind", String.class)
.addField("etag", String.class)
.addField("status", String.class)
.addField("htmlLink", String.class)
.addField("created", String.class)
.addField("updated", String.class)
.addField("summary", String.class)
.addField("description", String.class)
.addField("location", String.class)
.addRealmObjectField("creator", eventCreatorSchema)
.addRealmObjectField("organizer", organizerSchema)
.addRealmObjectField("start", startSchema)
.addRealmObjectField("end", endSchema)
.addField("transparency", String.class)
.addField("iCalUID", String.class)
.addField("sequence", Integer.class)
.addRealmListField("attendees", AttendeeSchema)
.addField("recurringEventId", String.class)
.addRealmObjectField("originalStartTime", originalStartTimeSchema)
.addRealmListField("recurrence", recurrenceSchema)
.addRealmObjectField("recurrenceDetail", EventRecurrenceDetailSchema);
oldVersion++;
}
}
}
组织者.java
public class Organizer extends RealmObject {
@PrimaryKey
private long Id;
@Index
private String email;
private String displayName;
private Boolean self;
...
}
Start.java
public class Start extends RealmObject {
@PrimaryKey
private long Id;
private String dateTime;
private String timeZone;
private String date;
public Start() {
}
}
End.java
public class End extends RealmObject {
@PrimaryKey
private long Id;
@SerializedName("dateTime")
@Expose
private String dateTime;
@SerializedName("timeZone")
@Expose
private String timeZone;
@SerializedName("date")
@Expose
private String date;
public End() {
}
}
EventCreator.java
public class EventCreator extends RealmObject {
@PrimaryKey
private String email;
private String displayName;
public EventCreator() {
}
}
Attendee.java
public class Attendee extends RealmObject {
@PrimaryKey
private String id;
private String email;
private String displayName;
private Boolean organizer;
private Boolean self;
private String responseStatus;
public Attendee() {
}
}
OriginalStartTime.java
public class OriginalStartTime extends RealmObject {
@PrimaryKey
private String id;
private String dateTime;
public OriginalStartTime() {
}
}
ReccurenceString.java
public class RecurrenceString extends RealmObject {
@PrimaryKey
private long Id;
private String recurrence;
public RecurrenceString() {
}
}
EventRecurrenceDetail.java
public class EventRecurrenceDetail extends RealmObject {
@PrimaryKey
private String id;
private int freq;
private int byDay;
private int byDayNum;
private String until;
private int interval;
public EventRecurrenceDetail() {
}
}
Item.java
public class Item extends RealmObject {
@PrimaryKey
private String id;
private String kind;
private String etag;
private String status;
private String htmlLink;
private String created;
private String updated;
private String summary;
private String description;
private String location;
private EventCreator creator;
private Organizer organizer;
private Start start;
private End end;
private String transparency;
private String iCalUID;
private Integer sequence;
private RealmList<Attendee> attendees = new RealmList<>();
private String recurringEventId;
private OriginalStartTime originalStartTime;
private RealmList<RecurrenceString> recurrence = new RealmList<>();
private EventRecurrenceDetail recurrenceDetail;
public EventRecurrenceDetail getRecurrenceDetail() {
return recurrenceDetail;
}
public Item() {
}
}
最佳答案
试试这个:
RealmObjectSchema organizerSchema = schema.create("Organizer")
.addField("Id", long.class, FieldAttribute.PRIMARY_KEY)
.addField("email", String.class)
.addField("displayName", String.class)
.addField("self", Boolean.class);
addPrimaryKey
必须在现有字段上调用。
---- 2016年1月22日更新删除特定版本的Realm文件----
DynamicRealm
旨在打开 Realm 文件而不检查架构。
如果你想删除版本0的Realm文件,你可以这样做:
File file = new File(realmConfig.getPath());
if (file.exist()) {
DynamicRealm dynamicRealm = DynamicRealm.getInstance(realmConfig);
long version = dynamicRealm.getVersion();
dynamicRealm.close();
if (version == 0) {
Realm.deleteRealm(realmConfig);
}
}
关于realm - 非法参数异常 : Field name doesn't exist on object while doing migration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34886660/
我在 SQL 查询中使用了一个简单的 IF NOT EXISTS/WHERE NOT EXISTS 语句(我都尝试过),但我总是收到 mysql 错误,不知道为什么。尝试使用不同的引号,检查我的 My
我有 2 个表:tbl1 和 tbl2。我想从 tbl1 返回一行,其中包含以下列:col1、col2、col3、can_be_deleted 、有重要项目。这个想法是,can_be_deleted
如果您是 "t1".persona_1_id = 2,则预期结果应返回 persona_id = 4。 like --- id persona_1_id persona_2_id liked 1 2
我遇到了这个用于执行幂等插入的 github SQL 代码示例。完全按照我想要的方式工作。我不想使用 EXISTS,因为我觉得它有点困惑。可以使用联接对相同的操作进行编码吗? 下面是我在 github
public bool CheckTblExist(string TblName) { try { string cmTxt = "s
表1 Id Name DemoID 1 a 33 2 b 44 3 c 33 4 d 33 5 e 44 表2 Id DemoID IsT
我对 SQL 非常陌生。我想知道当我使用“IF EXISTS”或“IF NOT EXISTS”时会发生什么。例如:以下两个语句有什么区别: 语句 1:(存在) IF EXISTS( SELECT OR
我正在更新 exist-db 集合中的 XML 文件,我必须检查是否存在 id 以决定是否必须在我的文档中替换或插入某些内容。 我注意到随着文件的增长,查询执行时间显着恶化,我决定为我的文件添加一个索
我有一个正在尝试更新的数据库,但我不明白为什么会收到有关不存在的列的奇怪错误。当我使用“heroku pg:psql”访问数据库时,我完全可以看到该列。我找到了couple其他questions遇到类
我有一个这样的查询 SELECT ... FROM ... WHERE (SELECT EXISTS (SELECT...)) which did not return anything th
我有一个可以对数据库执行插入和更新的程序,我从 API 获取数据。这是我得到的示例数据: $uname = $get['userName']; $oname = $get['offerNa
我的批处理文件中有这个脚本 -- if not exist "%JAVA_HOME%" ( echo JAVA_HOME '%JAVA_HOME%' path doesn't exist) -
有没有办法让 Directory.Exists/File.Existssince 区分大小写 Directory.Exists(folderPath) 和 Directory.Exists(folde
考虑使用这两个表和以下查询: SELECT Product. * FROM Product WHERE EXISTS ( SELECT * FROM Codes
我正在使用 Subclipse 1.6.18 使用 Eclipse 3.72 (Indigo) 来处理 SVN 1.6 存储库。这一切都在 Ubuntu 下运行。 我有一个项目,在我更新我的 Ecli
我正在尝试使用 Terraform 配置 Azure 存储帐户和文件共享: resource "random_pet" "prefix" {} provider "azurerm" { versi
我有兴趣为需要使用 NOT EXISTS 的应用程序编写查询。子句来检查一行是否存在。 我正在使用 Sybase,但我想知道一般 SQL 中是否有一个示例,您可以在其中编写具有 NOT EXISTS
我正在尝试使用 Terraform 配置 Azure 存储帐户和文件共享: resource "random_pet" "prefix" {} provider "azurerm" { versi
下面是代码示例: CREATE TABLE #titles( title_id varchar(20), title varchar(80)
我曾经这样编写 EXISTS 检查: IF EXISTS (SELECT * FROM TABLE WHERE Columns=@Filters) BEGIN UPDATE TABLE SET
我是一名优秀的程序员,十分优秀!