Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(1062, "Duplicate entry '0' for key 'PRIMARY'")

I'm getting this error (1062, "Duplicate entry '0' for key 'PRIMARY'"). This happened after I migrated my Django app from sqlite3 to MySQL. Here is the concerned table:

mysql> describe meddy1_specialization;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(30) | NO   |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

Here is the model:

class Specialization(models.Model):
    name = models.CharField(max_length=30)

    def __unicode__(self):
        return self.name

Here is the data in the table:

mysql> select * from meddy1_specialization;
+----+--------------------+
| id | name               |
+----+--------------------+
|  1 | Dentist            |
|  2 | Dermatologist      |
|  3 | Primary Care       |
|  4 | Ophthalmologist    |
|  5 | Pediatrician       |
|  6 | Orthopedist        |
|  7 | Ear, Nose & Throat |
|  8 | Gynecologist       |
|  9 | test               |
| 13 | test               |
| 14 | test1              |
+----+--------------------+
11 rows in set (0.00 sec)
like image 773
maahd Avatar asked Nov 11 '22 04:11

maahd


1 Answers

Could you check in your mysql database what the incrementation number is at? It seems that mysql is trying to insert a row with the same id.

like image 175
Eagllus Avatar answered Nov 14 '22 22:11

Eagllus