android - There is some sytax issue with CREATE_TASKS_TABLE String -
this code databasehelper class //these 2 tables
private static final string table_tasks = "tasks"; private static final string table_task_list = "task_list";   // these table columns names
private static final string key_pk = "_id"; private static final string key_title = "title"; private static final string key_details = "details"; private static final string key_notes = "notes"; private static final string key_fk_tasklist_id = "fk_tasklist_id";   //these strings assigned db.exesql
private static final string create_tasks_table = "create table " + table_tasks  + "("  + key_pk + " integer primary key autoincrement," + key_title + " text," + key_details + " text," + key_notes + " text,"  + " foreign key ("+ key_fk_tasklist_id + ")"  + "references "  + table_task_list + "("+ key_pk + ")"  + ")"; private static final string create_task_list_table = "create table " + table_task_list + "(" + key_pk + " integer primary key autoincrement," + key_title + " text" +    ")"; public void oncreate(sqlitedatabase db) { try { db.execsql(create_tasks_table);// create task table } catch (exception e) { log.e("oncreate error", "tasks_table not created"); } try { db.execsql(create_task_list_table);// create task list table } catch (exception e) { log.e("oncreate error", "task_list_table not created"); } }   string causing problem when try insert data says table tasks has no column named fk_tasklist_id
create table tasks (     _id integer primary key autoincrement,     title text,     details text,     notes text,     foreign key (fk_tasklist_id) references task_list(_id) )   in table definition, there indeed no column named fk_tasklist_id.
to define such column, add column list:
create table tasks (     _id integer primary key autoincrement,     title text,     details text,     notes text,     fk_tasklist_id integer,     foreign key (fk_tasklist_id) references task_list(_id) )   alternatively, put fk constraint on column:
create table tasks (     _id integer primary key autoincrement,     title text,     details text,     notes text,     fk_tasklist_id integer references task_list(_id) )      
Comments
Post a Comment