MySQL PHPMyAdmin错误#1062-键"PRIMARY"的条目"0"重复 [英] MySQL PHPMyAdmin Error #1062 - Duplicate entry '0' for key 'PRIMARY'

查看:331
本文介绍了MySQL PHPMyAdmin错误#1062-键"PRIMARY"的条目"0"重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我想添加主键id列,但会引发错误:

Now I want to add a primary key id column but it throws the error:

#1062-密钥"PRIMARY"的条目"0"重复

#1062 - Duplicate entry '0' for key 'PRIMARY'

我已经尝试过了: 将主键添加到现有表中

推荐答案

创建新列时,将分配默认值(在您的情况下为0),因此您需要指定将具有的值(除您可以将其告知列是自动递增的,它将为您完成行的新条目的工作). 您必须将所有值更改为不同的值,id键必须唯一

When you creates a new column, a default value is asigned (in your case will be 0), so you need to specify wich values will it have (besides you can tell it to the column to be autoincremental, and it will do the work for you for the new entries of rows). You have to change all the values to be differents between them, the id key MUST be unique

要更改所有ID,在mysql中,您可以执行以下操作:

To change all your ids, in mysql you can do:

SET @new_id=0;
UPDATE your_table
SET id = @new_id := @new_id + 1
where id = 0

这篇关于MySQL PHPMyAdmin错误#1062-键"PRIMARY"的条目"0"重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆