Mysql Unique record insertion problem

Asked

Viewed 620 times

4

I have a table that has a Unique field, I deleted a record of this table and now I want to insert it again, however Mysql generates the error: "Error Code: 1062. Duplicate entry '' for key '". How can I resolve this?

TABLE CREATE:

CREATE TABLE `bem` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `cpf` varchar(17) NOT NULL,
  ...
  PRIMARY KEY (`id`),
  UNIQUE KEY `cpf` (`cpf`)
) ENGINE=InnoDB AUTO_INCREMENT=1764 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

INSERT EXAMPLE:

INSERT INTO `bem` (cpf, ...)VALUES ('12312312312', ...);
  • Place create from table.

  • Pole the CREATE TABLE and also the query of INSERT what are you doing.

  • you have some column called excluido or ativo? pq basically Insert Cpf already exists in the table.

  • The record was actually deleted, giving a select nothing returns.

  • Was the deletion actually physical (delete) ? Delete and select was done in the same user section ? which error was reported ?

  • Yes was delete.

  • The error reported is : "Error Code: 1062. Duplicate entry '12312312312' for key 'cpf_UNIQUE'" . delete was made more than a month ago.

  • I would dump this table, create a new base and test again.

  • 1

    With dump works, but I don’t want to have to do this every time another error like this occurs.

  • This test is to know if table is not corrupted.

  • My friend, you better put the word out CREATE TABLE complete. Another thing, check if, when you generate the INSERT dynamically, all required fields are actually being populated with values.

Show 6 more comments

1 answer

0

Try running Mysql table repairer.

If it is a table using the engine InnoDb, just do this ALTER TABLEthat it will suffer a rebuild:

mysql> ALTER TABLE t1 ENGINE = InnoDB;

If it is a MyISAM, just do:

mysql> REPAIR TABLE t1;
  • Test it and it didn’t solve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.