mysql insert error 1062

痞子三分冷 提交于 2019-11-27 16:29:08
Mark Byers

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.

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.

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!