MySQL phpMyAdmin 错误 #1062 - 密钥 1 的重复条目“1”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3311427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:37:13  来源:igfitidea点击:

phpMyAdmin error #1062 - Duplicate entry '1' for key 1

mysqlphpmyadminmysql-error-1062

提问by Webne

I am not sure why I am getting this error #1062 - Duplicate entry '1' for key 1 cany any one help explain what it means. Thanks

我不确定为什么我会收到此错误 #1062 - 密钥 1 的重复条目 '1' 任何人都可以帮助解释它的含义。谢谢

回答by bradenkeith

More than likely your column is set to be Unique, and you're trying to input a row with an ID that already exists in your table.

您的列很可能设置为唯一,并且您尝试输入的行的 ID 已存在于您的表中。

回答by Pekka

You are probably trying to insert a record with the ID (or some other field) 1set, while such a record already exists in the table. The field that is the primary key must have a unique value for each record.

您可能正在尝试插入带有 ID(或某些其他字段)1集的记录,而此类记录已存在于表中。作为主键的字段对于每条记录都必须具有唯一值。

回答by Eduardo Rascon

I think you're trying to insert '1' to a unique key field that already has a '1' value

我认为您正在尝试将“1”插入到已经具有“1”值的唯一键字段中

回答by bito_

The problem is related with your file - you are trying to create a DB using a copy - at the top of your file you will find something like this:

问题与您的文件有关 - 您正在尝试使用副本创建数据库 - 在文件顶部,您会发现如下内容:

CREATE DATABASE IF NOT EXISTS *THE_NAME_OF_YOUR_DB*DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci; USE *THE_NAME_OF_YOUR_DB*;

如果不存在,则创建数据库*THE_NAME_OF_YOUR_DB*默认字符集 latin1 COLLATE latin1_general_ci; 使用*THE_NAME_OF_YOUR_DB*;

and I'm sure that you already have a DB with this name - IN THE SAME SERVER - please check.

而且我确定您已经有一个同名的数据库 - 在同一个服务器中 - 请检查。

回答by ska

You need to add primary key with the group in which one primary key must be unique value. e.g. if a table has 4 columns id, name, address, group_id where group_id has duplicate value , if I want to add group_id as primary then that should be in a group consist with id and group_id

您需要在其中一个主键必须是唯一值的组中添加主键。例如,如果一个表有 4 列 id、name、address、group_id,其中 group_id 有重复值,如果我想将 group_id 添加为主要的,那么它应该在一个包含 id 和 group_id 的组中