0

I have a column in my SQLite database for saving student information (id, profile image path, age and description), then I also have a column for saving video path and thumbnail path specific to the student.

My question is, is it possible to have 2 ids in one column as below:

private static final String CREATE_STUDENT_SPESIFIC = " create table STUDENT_SPESIFIC ( _id TEXT , _viewHolderID INTEGER PRIMARY KEY AUTOINCREMENT , _THUMB_PATH TEXT , _VIDEO_PATH TEXT );";

_id is for when I want to get all video's and thumbnails for specific student (the student ID) and _viewHolderID is to get the specific video and thumbnail to the specific student.

I want to _viewHolderID to AUTOINCREMENT because the student will keep adding to the specific student and I want to be able to rename a specific video name.

I have tried to do so as above but I get the following error:

abort at 12 in [INSERT INTO STUDENT_SPESIFIC(_THUMB_PATH,_VIDEO_PATH,_viewHolderID,_id) VALUES (?,?,?,?)]: UNIQUE constraint failed: STUDENT_SPESIFIC._viewHolderID android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: STUDENT_SPESIFIC._viewHolderID (code 1555)

0

1 Answer 1

2

You're trying to insert a value in an AUTOINCREMENT field. Try to skip the field _viewHolderID when you insert new records by using

INSERT INTO STUDENT_SPESIFIC(_THUMB_PATH,_VIDEO_PATH,_id) VALUES (?,?,?)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.