mysql错误:主键的条目重复

ukdjmx9f  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(529)

sql查询:
正在转储表的数据 new_recipe ```
INSERT INTO new_recipe (id, post_title, post_image, post_author, post_date, post_desc) VALUES
(4, 'Daal Chawal', 'DDAa.jpg', 'Asad Khan', '2016-05-29', '\r\n Gujranwala agr pyara na hota\r\n\r\nGulshan Iqbal Park ka nizara na hota\r\n\r\nBypass pr ishara na hota\r\n\r\nSialkoti drwazy ka shara na hota\r\n\r\nPace pr janay ka mode dobara na hota\r\n\r\nBashir k dal chawal ka swad krara na hota\r\n\r\nsb Sattelite Town Girls Collage ka ksoor hai\r\n\r\nw\r\na Gujranwala ka koi larrka aawara na hota("\r\n\r\nGeo Gujranwala'),
(5, 'Daal Makhani', 'maxresdefault.jpg', 'Waqas Ali', '2016-05-29', '\r\n siosadflwq r0ewlk hopxcyfsajr w4dfwsaf654wq13\r\nt1sd3v5sa +et5wq+e f80w+e5t+eqd7fv+6sd1v 3x4c6\r\n5v321d35g 02df6s0+52wer+t q032va0sd')
MySQL said: Documentation

1062 - Duplicate entry '4' for key 'PRIMARY'

这是我的mysql查询
表的表结构 `new_recipe` ```
CREATE TABLE IF NOT EXISTS new_recipe (
  id int(10) NOT NULL,
  post_title varchar(250) NOT NULL,
  post_image varchar(250) NOT NULL,
  post_author varchar(250) NOT NULL,
  post_date date NOT NULL,
  post_desc text NOT NULL,
  PRIMARY KEY (id)
) AUTO_INCREMENT=6 ;

正在转储表的数据 new_recipe ```
INSERT INTO new_recipe (id, post_title, post_image, post_author, post_date, post_desc) VALUES
(4, 'Daal Chawal', 'DDAa.jpg', 'Asad Khan', '2016-05-29', '\r\n Gujranwala agr pyara na hota\r\n\r\nGulshan Iqbal Park ka nizara na hota\r\n\r\nBypass pr ishara na hota\r\n\r\nSialkoti drwazy ka shara na hota\r\n\r\nPace pr janay ka mode dobara na hota\r\n\r\nBashir k dal chawal ka swad krara na hota\r\n\r\nsb Sattelite Town Girls Collage ka ksoor hai\r\n\r\nw\r\na Gujranwala ka koi larrka aawara na hota("\r\n\r\nGeo Gujranwala'),
(5, 'Daal Makhani', 'maxresdefault.jpg', 'Waqas Ali', '2016-05-29', '\r\n siosadflwq r0ewlk hopxcyfsajr w4dfwsaf654wq13\r\nt1sd3v5sa +et5wq+e f80w+e5t+eqd7fv+6sd1v 3x4c6\r\n5v321d35g 02df6s0+52wer+t q032va0sd');

phpmyadmin错误的图像`
1tu0hz3e

1tu0hz3e1#

在第二个转储数据库中,您使用相同的id,它已经存在于“new\u recipe”中,这就是为什么它显示重复条目的原因。
代码:

CREATE TABLE IF NOT EXISTS new_recipe (
                        id int(10) NOT NULL AUTO INCREMENT,
                        post_title varchar(250) NOT NULL,
                        post_image varchar(250) NOT NULL,
                        post_author varchar(250) NOT NULL,
                        post_date date NOT NULL,
                        post_desc text NOT NULL,
                        PRIMARY KEY (id)
                       ) AUTO_INCREMENT=6 ;

INSERT INTO `new_recipe` (`id`, `post_title`, `post_image`, `post_author`, `post_date`, `post_desc`) VALUES
('', 'Daal Chawal', 'DDAa.jpg', 'Asad Khan', '2016-05-29', '\r\n Gujranwala agr pyara na hota\r\n\r\nGulshan Iqbal Park ka nizara na hota\r\n\r\nBypass pr ishara na hota\r\n\r\nSialkoti drwazy ka shara na hota\r\n\r\nPace pr janay ka mode dobara na hota\r\n\r\nBashir k dal chawal ka swad krara na hota\r\n\r\nsb Sattelite Town Girls Collage ka ksoor hai\r\n\r\nw\r\na Gujranwala ka koi larrka aawara na hota("\r\n\r\nGeo Gujranwala'),
('', 'Daal Makhani', 'maxresdefault.jpg', 'Waqas Ali', '2016-05-29', '\r\n   siosadflwq r0ewlk hopxcyfsajr w4dfwsaf654wq13\r\nt1sd3v5sa +et5wq+e f80w+e5t+eqd7fv+6sd1v 3x4c6\r\n5v321d35g 02df6s0+52wer+t q032va0sd');

添加自动增量,在插入数据的过程中,将自动增量的id留空。

相关问题