MySQL上主键的重复条目 [英] Duplicate entry for primary key on MySQL
问题描述
我的表只有一列 ID
(用于管理员登录的密码)
My table just has single column ID
(passwords for admin Log-in)
因为此代码运行每次程序启动时,通过使用创建数据库
和创建表
时发生错误。 >如果不是EXIXTS 语句。
Because this code runs every time that program starts, I can prevent errors occurs on creating database
and creating tables
by using IF NOT EXIXTS
statement.
由于 adminLogin
表应该是首次初始化,当用户重新运行程序时,出现主键重复条目
错误。
Since adminLogin
table should be initial first time, When user re-run the program, the Duplicate entry for primary key
error occurs.
我使用了如果不存在
可以插入表中,但是还有另一个错误!
I used IF NOT EXISTS
for inserting into table, But there is some another error!
我的表:
错误:
推荐答案
您正在尝试插入相同的值。
PK应该是唯一的。
You are trying to insert same value. PK should be unique.
设置ID为自动增量。
SET ID as autoincrement.
CREATE TABLE `table_code` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`your_column` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
这篇关于MySQL上主键的重复条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!