MySQL的错误:重复的条目主键(MySQL Error: Duplicate entry for

2019-10-28 22:44发布

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的错误的图像 `

Answer 1:

在第二倾销数据库,您使用它已经在“new_recipe”这就是为什么它显示重复条目存在相同的ID。

码:

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。



文章来源: MySQL Error: Duplicate entry for Primary Key