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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With