Why this Dump fail on import?
This is my table with data :
CREATE TABLE IF NOT EXISTS `categories` (
`id` int(11) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`user` varchar(255) NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
--
-- Dump dei dati per la tabella `categories`
--
INSERT INTO `categories` (`id`, `name`, `user`, `date`) VALUES(1, 'K-Bal Sound System', 'djfonplaz', '0000-00-00 00:00:00');
INSERT INTO `categories` (`id`, `name`, `user`, `date`) VALUES(2, 'Network23 Mixtapes', 'djfonplaz', '0000-00-00 00:00:00');
INSERT INTO `categories` (`id`, `name`, `user`, `date`) VALUES(3, 'Artskorps Webmix', 'djfonplaz', '0000-00-00 00:00:00');
INSERT INTO `ca开发者_高级运维tegories` (`id`, `name`, `user`, `date`) VALUES(4, 'GTW Users Mixes', 'djfonplaz', '0000-00-00 00:00:00');
INSERT INTO `categories` (`id`, `name`, `user`, `date`) VALUES(5, 'Underground Music Tapes', 'djfonplaz', '0000-00-00 00:00:00');
INSERT INTO `categories` (`id`, `name`, `user`, `date`) VALUES(6, 'UK Main Events', 'djfonplaz', '0000-00-00 00:00:00');
INSERT INTO `categories` (`id`, `name`, `user`, `date`) VALUES(7, 'Gabba Nation, Bunker & Box, German Events', 'djfonplaz', '0000-00-00 00:00:00');
When I try to import this (with HeidiSql 6.0) I get this error :
/* SQL Error (1062): Duplicate entry '1' for key 1 */
?
Table categories
has to exist and there already is data.
Remove categories
table before executing that script.
if you set auto_increment
on primary key, remove the id
in INSERT
statements
INSERT INTO `categories` (`name`, `user`, `date`) VALUES('K-Bal Sound System', 'djfonplaz', '0000-00-00 00:00:00');
...
You are inserting a value for your auto increment field. MySQL will automatically insert a value into that field for you so you do not have to try set the value yourself. As it tries to insert your first row it will try to input 1 over the auto increment's value 1.
To fix just remove the id column from your insert.
精彩评论