标签: android-orm

Android Room FOREIGN KEY约束失败

我试图在Android SQLite中设计和实现文件夹树结构,借助Google在I/O 2017中引入的Android Room Persistence(一种ORM).在我的设计中,一个文件夹可以包含另一个文件夹和文件.这是我的文件夹和文件的代码:

文件模型:

@Entity(tableName = "files", foreignKeys = @ForeignKey(entity = Folder.class,
    parentColumns = "id",
    childColumns = "parent_id",
    onDelete = CASCADE))
public class File {
    @PrimaryKey(autoGenerate = true)
    private int id;

    private String title;
    private Date creationDate;

    @ColumnInfo(name = "parent_id")
    public int parentId;

    //here setters and getters skipped but exist in original code
}
Run Code Online (Sandbox Code Playgroud)

这是文件夹代码:

@Entity(tableName = "folders", foreignKeys = @ForeignKey(entity = Folder.class,
    parentColumns = "id",
    childColumns = "parent_id",
    onDelete = CASCADE,onUpdate = SET_NULL))
public class Folder { …
Run Code Online (Sandbox Code Playgroud)

sqlite orm android android-orm android-room

14
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

android-orm ×1

android-room ×1

orm ×1

sqlite ×1