I have two existing tables, workTable and table_jobs. I want to update my workTable and create a relationship with table_jobs with a default value. This is what I tried:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
switch (oldVersion){
case 3:{
int jobid = insertJobWithoutClosing(new Job("Default", Color.rgb(0, 0, 255)), db);
db.execSQL("ALTER TABLE " + workTable + " ADD COLUMN " + colJobID + " INTEGER DEFAULT " + jobid + " FOREIGN KEY("+colJobID+") REFERENCES "+table_jobs+"("+job_ID+")");
}
}
This gives me the following exception:
android.database.sqlite.SQLiteException: near "FOREIGN": syntax error (code 1): , while compiling: ALTER TABLE WorkObjects ADD COLUMN JobID INTEGER DEFAULT 1 FOREIGN KEY(JobID) REFERENCES Jobs(jobsID)
What is wrong?