我想使用 room 在我的数据库中添加一个新列。我使用 Room 的迁移将我的数据库迁移到新版本,但它无法正常工作。INTERGER 字段的默认 notnull 值为 true ,这对我来说真的很麻烦。请帮我。我已经坚持了很多小时。
我有一个位置类。
package com.example.phamf.javamvvmapp.Model;
import ...
@Entity (tableName = "location")
public class Location {
@PrimaryKey(autoGenerate = true)
private int id;
private float x;
private float y;
private String name;
public Location(int id, float x, float y, String name) {
this.id = id;
this.x = x;
this.y = y;
this.name = name;
}
public Location () {
}
// Getter and setter
}
Run Code Online (Sandbox Code Playgroud)
我想添加一个名为 type 的新字段,它的类型是 INTEGER,所以我修改了上面的 Location.java 文件,例如
package com.example.phamf.javamvvmapp.Model;
import …Run Code Online (Sandbox Code Playgroud)