AnRu
AnRu

Reputation: 67

android foreign key. program crashes

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 );";

my logcat is as: 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: unknown column "tid" in foreign key definition (code 1): , while compiling: create table alarms(_aid integer primary key autoincrement, FOREIGN KEY (tid) REFERENCES tasks ( _id ), days text not null );

pls help me find the error!! why doe my prgram crash??

Upvotes: 0

Views: 442

Answers (1)

Naveen Kumar
Naveen Kumar

Reputation: 3818

try this query.

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

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

Upvotes: 3

Related Questions