maa*_*ahd 5 mysql django primary-key duplicates auto-increment
我收到了这个错误(1062, "Duplicate entry '0' for key 'PRIMARY'").这是在我将我的Django应用程序从sqlite3迁移到MySQL之后发生的.这是关注的表:
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)
Run Code Online (Sandbox Code Playgroud)
这是模型:
class Specialization(models.Model):
name = models.CharField(max_length=30)
def __unicode__(self):
return self.name
Run Code Online (Sandbox Code Playgroud)
这是表中的数据:
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)
Run Code Online (Sandbox Code Playgroud)