I am trying to create a database which allows users to create \'to do\' lists and fill them with items to complete. However, when inserting data into the tables it gives me
You get a UNIQUE constraint failed
error when the data that you are inserting has an entry which is already in the corresponding column of the table that you are inserting into.
If you want SQL to IGNORE that error and continue adding other records , then do this :
INSERT or IGNORE into tablename VALUES (value1,value2 , so on );
If you want to replace the values in the table whenever the entry already exists , then do this:
INSERT or REPLACE into tablename VALUES (value1,value2 , so on );
This saves lot of processing on your part and quite useful.
You have set list_id to be the primary key on the list table, which means that value must be unique for each record. Trying to insert multiple records with the same list_id table is therefore causing the error.
The issue is the same for the item table.