In Android, does _id have to be present in any table created?
- by Andy
I am trying to create a table to only has a foreign key, not a primary key. I am getting this error:
java.lang.IllegalArgumentException: column '_id' does not exist
I read a tutorial that the primary key must be _id, with no explanation. And that is fine. But what if I do not want a primary key! What if I only want a foreign key. I am assuming this is where my problem lies. The schemas below are what I have. But the third one is where I assume this is coming from.
database.execSQL("CREATE TABLE events (" +
"_id INTEGER PRIMARY KEY, event_name TEXT" +
")");
database.execSQL("CREATE TABLE reminders(_id INTEGER PRIMARY KEY, event_name TEXT" +
")");
database.execSQL("CREATE TABLE events_info (_id INTEGER, event_name TEXT, all_day INTEGER, " +
"start_date INTEGER, start_time INTEGER, end_date INTEGER, end_time INTEGER," +
" location TEXT, reminder_id INTEGER, notes TEXT, repeat TEXT," +
"FOREIGN KEY(_id) REFERENCES events(_id), FOREIGN KEY(reminder_id) REFERENCES reminders(_id))"
);