Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room 数据库的问题 #17

Open
yougaohui opened this issue Dec 19, 2019 · 1 comment
Open

Room 数据库的问题 #17

yougaohui opened this issue Dec 19, 2019 · 1 comment

Comments

@yougaohui
Copy link

@database(entities = {User.class, Bus.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {

public abstract UserDao userDao();

public abstract BusDao busDao();

public static AppDatabase get(AppComponent component) {
    return (AppDatabase) component.dbManager().database();
}

}

@entity(tableName = "Bus")
public class Bus {
@PrimaryKey(autoGenerate = true)
private int ids;
@SerializedName("name")
String name;

public int getIds() {
    return ids;
}

public void setIds(int ids) {
    this.ids = ids;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

@entity(tableName = "User")
public class User {

@PrimaryKey(autoGenerate = true)
private int id;

// ID
@SerializedName("userId")
private String userId;

// 名字
@ColumnInfo(name = "name")
private String name;

// 排除这个字段,不存入数据库
@Ignore
Bitmap bitmap;

public User() {

}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Bitmap getBitmap() {
    return bitmap;
}

public void setBitmap(Bitmap bitmap) {
    this.bitmap = bitmap;
}

}
我这样操作数据库,要抛出Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.这个异常。难道这个框架只能初始化一个类在AppDatabase 里面吗?可以qq联系你吗沟通一下这个心数据库的用法,我网上查了很多资料,都没发现什么原因导致的,有的说是数据库更新。感觉不是那么回事啊

@yougaohui
Copy link
Author

@database(entities = {User.class, Bus.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {

public abstract UserDao userDao();

public abstract BusDao busDao();

public static AppDatabase get(AppComponent component) {
    return (AppDatabase) component.dbManager().database();
}

}

@entity(tableName = "Bus")
public class Bus {
@PrimaryKey(autoGenerate = true)
private int ids;
@SerializedName("name")
String name;

public int getIds() {
    return ids;
}

public void setIds(int ids) {
    this.ids = ids;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

@entity(tableName = "User")
public class User {

@PrimaryKey(autoGenerate = true)
private int id;

// ID
@SerializedName("userId")
private String userId;

// 名字
@ColumnInfo(name = "name")
private String name;

// 排除这个字段,不存入数据库
@Ignore
Bitmap bitmap;

public User() {

}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Bitmap getBitmap() {
    return bitmap;
}

public void setBitmap(Bitmap bitmap) {
    this.bitmap = bitmap;
}

}
我这样操作数据库,要抛出Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.这个异常。难道这个框架只能初始化一个类在AppDatabase 里面吗?可以qq联系你吗沟通一下这个心数据库的用法,我网上查了很多资料,都没发现什么原因导致的,有的说是数据库更新。感觉不是那么回事啊

找到原因了,原来数据库文件保存到sd卡根目录里面,没删除,我卸载后也删除不了,所以一直用的第一次初始化那个表的数据库,需要手动删除才行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant