0
public static final String TABLE_TASKS = "tasks";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_TASK = "task";
public static final String COLUMN_TIME = "time";
public static final String COLUMN_INITDATE = "initdate";
public static final String COLUMN_PRIORITY="priority";

public static final String TABLE_REPEAT = "alarms";
public static final String COLUMN_AID = "_aid";
public static final String COLUMN_TID = "tid";

公共静态最终字符串 COLUMN_DAYS=“天”;

private static final String DATABASE1_CREATE = "create table " + TABLE_TASKS + "("
+ COLUMN_ID + " integer primary key autoincrement, "+ COLUMN_TASK
+ " text not null, "+ COLUMN_TIME+" integer not null, "+ COLUMN_INITDATE+" integer not null, "+ COLUMN_PRIORITY +" integer );";

private static final String DATABASE2_CREATE = "create table " + TABLE_REPEAT + "("
        + COLUMN_AID + " integer primary key autoincrement, "+  " FOREIGN KEY (" + COLUMN_TID + ") REFERENCES " + TABLE_TASKS + " ( " + COLUMN_ID + " ), "+ COLUMN_DAYS + " text not null );";

我的 logcat 为:03-06 09:17:07.051: E/AndroidRuntime(1029): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.habitator/com.example.habitator.Habitator}: android. database.sqlite.SQLiteException:外键定义中的未知列“tid”(代码1):,编译时:创建表警报(_aid整数主键自动增量,外键(tid)参考任务(_id),天文本不为空) ;

请帮我找出错误!为什么我的程序崩溃?

4

1 回答 1

3

试试这个查询。

create table alarms(_aid integer primary key autoincrement, tid integer FOREIGNKEY REFERENCES tasks ( _id ), days text not null );

https://www.sqlite.org/foreignkeys.html

于 2013-03-06T09:38:16.510 回答