mysql insert error 1062

后端 未结 5 1319
名媛妹妹
名媛妹妹 2020-12-04 04:31

SQL query:

INSERT INTO  `website_categorization`.`category_keyword` (
`ID` ,
`ID_Category` ,
`Keyword` ,
`Score`)
VALUES (
NULL ,  \'18\',  \'free mail\',  \         


        
相关标签:
5条回答
  • 2020-12-04 04:33

    Well, it means that the data you are inserting breaks the unique constraints. From the error messasge I'd say some data already exists with the pair (18, 'free mail') - you say that is constrained to be unique.

    The row number is not an indication, because it doesn't correspond to the key.

    0 讨论(0)
  • 2020-12-04 04:44

    Your ID_category key is declared as unique and thus you cannot have two entries with the same value.

    0 讨论(0)
  • 2020-12-04 04:51

    If your ID field is truly a primary key, it is mostly likely (or should be) auto-incremented. So leave that field out of the INSERT query.

    0 讨论(0)
  • 2020-12-04 04:58

    You already have a row in your database with the values '18' and 'free mail'. You can't have two such rows because of the unique constraint. You have some choices:

    • Remove the original row and try your insert again: DELETE FROM yourtable WHERE ID_Category = '18' AND Keyword = 'free mail'.
    • Remove the unique constraint to allow both rows to exist.
    • Use INSERT IGNORE to ignore the error.
    • Use REPLACE instead of INSERT to replace the old row with the new row.
    • Attempt the INSERT knowing that the client-side will be alerted of the error.
    0 讨论(0)
  • 2020-12-04 05:00

    That is MySQL Error number 1062, not row number. The error means duplicate entry. You are inserting NULL and '18' twice in ID and ID_Category respectively, so it will throw this error the 2nd time you do it. ID_Category is very likely the name of your index. You can do a

    show index from website_categorization.category_keyword

    to see the index name.

    0 讨论(0)
提交回复
热议问题