mysql - Error Code: 1062 Duplicate entry for key 'PRIMARY' -


i getting error code 1062: duplicate entry. first row insert, fails on same id. everytime hit execute increment: 1466, 1467, 1468, 1469. , each time there same record entered, assuming autoincrement working first iteration.

table:

'entity':    create table `entity` (     `id` int(11) not null auto_increment,   `name` varchar(255) not null,     `reg_num` varchar(45) not null,     `enterprise_id` int(11) default null,     primary key (`id`) ) engine=innodb auto_increment=1474 default charset=latin1 comment=\'comment' 

stored procedure:

delimiter $$  create definer=`root`@`localhost` procedure `tp_to_entityproc`()     deterministic     comment 'stored' begin     declare done boolean default 0;     declare tid int;     declare tt_name text;      declare allt cursor                  select training_provider_id, training_provider_name                  training_providers;      declare continue handler not found set done=1;      open allt;     read_loop: loop         if done              leave read_loop;         end if;          fetch allt tid, tt_name;          set @id = 0;         set @t_name = 0;         set @id = tid;         set @t_name = tt_name;         set @empty = '';          if (@id != 0)             insert entity (name)             values (@t_name);             set @my_id = last_insert_id();              if @my_id != 0                 update training_awarded_providers                  set training_awarded_provider_id = @my_id                 training_awarded_provider_id = @id;             end if;         end if;      end loop;     close allt;   end 

not sure exact error of duplicate entry posted code not going work.

your table schema

create table `entity` (     `id` int(11) not null auto_increment,   `name` varchar(255) not null,     `reg_num` varchar(45) not null <-- here it's non null column 

in store procedure trying insert null reg_num column never succeed

if (@id != 0) insert entity (name) values (@t_name); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -