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";
public static final String COLUMN_DAYS =“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:无法启动活动ComponentInfo {com.example.habitator / com.example.habitator.Habitator}:android.database.sqlite.SQLiteException :外键定义中的未知列“tid”(代码1):,同时编译:创建表警报(_aid整数主键自动增量,FOREIGN KEY(tid)REFERENCES任务(_id),天文本不为空);
请帮我找错!为什么我的prgram崩溃?
答案 0 :(得分:3)
尝试此查询。
create table alarms(_aid integer primary key autoincrement, tid integer FOREIGNKEY REFERENCES tasks ( _id ), days text not null );