Skip to content

Room 数据库的问题 #17

@yougaohui

Description

@yougaohui

@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联系你吗沟通一下这个心数据库的用法,我网上查了很多资料,都没发现什么原因导致的,有的说是数据库更新。感觉不是那么回事啊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions