外键 Android 不工作

Foreign Key Android Not Working

categories(id, name, slug);
places(id, name, cat_id(foreignKey));

当我使用

查询table时
String where = "cat_id = ?";
String[] whereArgs = new String[]{"1488764085"}; 
c = db.query("places", new String[]{"name", "cat_id"}, where, whereArgs, null, null, null);

返回的 Cursor 有项目,但是当我在 where 子句中追加另一个字段时,就像在 Cursor 下面 returns 计数 -1

String where = "name = ? AND cat_id = ?";
String[] whereArgs = new String[]{"xxx", "1488764085"}; 
c = db.query("places", new String[]{"name", "cat_id"}, where, whereArgs, null, null, null);

谁能指出发生这种情况的实际问题

注:table 处有一个值为 "xxx" 的字段。

此问题已修复并发布,以便对其他人有所帮助。

通过为外键添加 ON DELETE CASCADE 实际上解决了我的问题。

foreign key cat_id references categories(id) ON DELETE CASCADE;