dabadaba
dabadaba

Reputation: 9512

Duplicate entry for key phpmyadmin

I am trying to insert new rows in my table and I got an erro I never had before, no idea why, this is it:

#1062 - Duplicate entry '24' for key 'usuario_id_2' 

My query:

INSERT INTO `mydb`.`votos` (`id`, `usuario_id`, `ciudad_candidata_id`, `voto`) VALUES (NULL, '24', '1', '1')

usuario_id is a foreign key, I have used it before in other tables and never had this problem. I don't understand what the error means and why it's happening.

Any help?

Upvotes: 0

Views: 1675

Answers (1)

Barmar
Barmar

Reputation: 780869

The error means that the usuario_id column is declared to be unique in the votos table, and there's already a row with 24 in that column. If it's not supposed to be unique in this table, fix your table schema. You probably should configure it with an ordinary index, not a unique index.

Upvotes: 3

Related Questions