SQLite3 UNIQUE constraint failed error

后端 未结 2 673
广开言路
广开言路 2020-12-08 21:38

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

2条回答
  •  离开以前
    2020-12-08 21:55

    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.

提交回复
热议问题