我一直试图在我的Android SQLite数据库中使用外键。 我尝试了以下语法,但它给了我一个逼近的力量:
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和名称。
编辑:
这是错误:
03-13 13:42:35.389: 错误/ AndroidRuntime(312):原因: android.database.sqlite.SQLiteException: 国外的未知列“ taskCat” 关键定义:创建表提醒 (_id整数主键 自动递增,而不是task_title文本 null,注释文本不为null, hinter_date_time文字不为null, 外键(taskCat)参考 类别(_id));