descri-6ren">
gpt4 book ai didi

mysql - (1062, "Duplicate entry ' 0' for key ' 主'")

转载 作者:可可西里 更新时间:2023-11-01 07:08:57 24 4
gpt4 key购买 nike

我收到此错误 (1062,“键‘PRIMARY’的重复条目‘0’”)。这发生在我将我的 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)

这是模型:

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

def __unicode__(self):
return self.name

这是表中的数据:

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)

最佳答案

你能在你的 mysql 数据库中检查增量数字是多少吗?看来 mysql 正在尝试插入具有相同 id 的行。

关于mysql - (1062, "Duplicate entry ' 0' for key ' 主'"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24739440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com