如何在Room Database中运行迁移以更改主键?

时间:2018-02-01 10:07:21

标签: android android-room

这是我的表格:id列是主键。我想将Doorway idid设为复合键Room支持吗?如果它确实如何做到这一点?

新的主键应该是复合,应该是这样的:

primary key = id+doorway_id

我的实体:

@Entity(tableName = "hours")
public class Hour extends EntityModel implements Parcelable {
    @SerializedName("id")
    @ColumnInfo(name = COLUMN_ID)
    @PrimaryKey()
    @Expose()
    private int _id;

    // Need to discuss.
    @SerializedName("server_id")
    @ColumnInfo(name = COLUMN_SERVER_ID)
    private int serverId;

    @SerializedName("entries")
    @ColumnInfo(name = COLUMN_ENTRIES)
    @Expose()
    private float entries;

    @SerializedName("alerts")
    @ColumnInfo(name = COLUMN_ALERTS)
    @Expose()
    private float alerts;

    @SerializedName("mag_level")
    @ColumnInfo(name = COLUMN_MAG_LEVEL)
    @Expose()
    private float magLevel;

    @SerializedName("door_open")
    @ColumnInfo(name = COLUMN_DOOR_OPEN)
    @Expose()
    private float doorOpen;

    @SerializedName("entryway_usage")
    @ColumnInfo(name = COLUMN_ENTRYWAY_USAGE)
    @Expose()
    private float entrywayUsage;

    @SerializedName("year")
    @ColumnInfo(name = COLUMN_YEAR)
    @Expose()
    private int year;

    @SerializedName("month")
    @ColumnInfo(name = COLUMN_MONTH)
    @Expose()
    private int month;

    @SerializedName("day")
    @ColumnInfo(name = COLUMN_DAY)
    @Expose()
    private int day;

    @SerializedName("hour")
    @ColumnInfo(name = COLUMN_HOUR)
    @Expose()
    private int hour;

    @SerializedName("alert_rate")
    @Expose
    @ColumnInfo(name = COLUMN_ALERT_RATE)
    private double alert_rate;

    @SerializedName("recorded_at")
    @Expose
    @ColumnInfo(name = COLUMN_TIME_STAMP)
    private String recorded_at;

    @SerializedName("doorway_id")
    @ColumnInfo(name = COLUMN_DOORWAY_ID)
    @Expose()
    private int doorway_id;
}

0 个答案:

没有答案