SQlite – Android – 外键语法
发布时间:2020-12-12 19:18:44 所属栏目:百科 来源:网络整理
导读:我一直在试图让外键在我的Android SQLite数据库中工作。我试过下面的语法,但它给了我一个力close: private static final String TASK_TABLE_CREATE = "create table " + TASK_TABLE + " (" + TASK_ID + " integer primary key autoincrement," + TASK_TITL
我一直在试图让外键在我的Android SQLite数据库中工作。我试过下面的语法,但它给了我一个力close:
private static final String TASK_TABLE_CREATE = "create table " + TASK_TABLE + " (" + TASK_ID + " integer primary key autoincrement," + TASK_TITLE + " text not null," + TASK_NOTES + " text not null," + TASK_DATE_TIME + " text not null,FOREIGN KEY ("+TASK_CAT+") REFERENCES "+CAT_TABLE+" ("+CAT_ID+"));"; 任何想法我可能做错了什么?如果你需要看到其他表结构,那么我可以,它只是一个非常简单的结构,第二个具有ID和名称。 编辑: 这里是错误: 您必须首先定义TASK_CAT列,然后在其上设置外键。 private static final String TASK_TABLE_CREATE = "create table " + TASK_TABLE + " (" + TASK_ID + " integer primary key autoincrement," + TASK_TITLE + " text not null," + TASK_NOTES + " text not null," + TASK_DATE_TIME + " text not null," + TASK_CAT + " integer," + " FOREIGN KEY ("+TASK_CAT+") REFERENCES "+CAT_TABLE+"("+CAT_ID+"));"; 更多信息,你可以找到sqlite外键doc。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |