我遇到了错误
Caused by: java.lang.IllegalStateException: Migration didn't properly handle memolist(com.jakchang.savelocation.Entity.MemoEntity).
Expected:
TableInfo{name='memolist', columns={date=Column{
name='date', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'}, fontType=Column{name='fontType', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
address=Column{name='address', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
nation=Column{name='nation', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
city=Column{name='city', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
latitude=Column{name='latitude', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
title=Column{name='title', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
uri2=Column{name='uri2', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
uri3=Column{name='uri3', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
uri1=Column{name='uri1', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
isDeleted=Column{name='isDeleted', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
id=Column{name='id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'},
tag=Column{name='tag', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
text=Column{name='text', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
uri4=Column{name='uri4', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
longitude=Column{name='longitude', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'}},
foreignKeys=[], indices=[]}
Found:
我想我写的是正确的实体..但是我得到了错误。 我在mvvm中使用livedata。 请让我知道解决这个问题。...
Entity
@Entity(tableName = "memolist")
public class MemoEntity {
@PrimaryKey(autoGenerate = true)
@NonNull
int id;
@ColumnInfo(name ="latitude")
String latitude;
@ColumnInfo(name ="longitude")
String longitude;
@ColumnInfo(name ="nation")
String nation;
@ColumnInfo(name ="city")
String city;
@ColumnInfo(name ="address")
String address;
@ColumnInfo(name ="title")
String title;
@ColumnInfo(name ="tag")
String tag;
@ColumnInfo(name ="date")
String date;
@ColumnInfo(name ="uri1")
String uri1;
@ColumnInfo(name ="uri2")
String uri2;
@ColumnInfo(name ="uri3")
String uri3;
@ColumnInfo(name ="uri4")
String uri4;
@ColumnInfo(name ="text")
String text;
@ColumnInfo(name ="fontType")
String fontType;
@ColumnInfo(name ="isDeleted")
String isDeleted;
public MemoEntity(){}
getter/setter~~
}
匹配下面的tableinfo序列和实体序列是否重要? 很难独自学习... 我真的想解决这个问题...
答案 0 :(得分:2)
检查错误消息,尤其是 except 和 found 之间的差异。迁移脚本中的默认值可能是一个问题。
例如,使用Room 2.1.0在我的实体中添加一个新整数,我已经设置了默认值:
object MIGRATION_1_2 : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE entity ADD COLUMN newInteger INTEGER NOT NULL DEFAULT 0")
}
}