【问题标题】:inserting into table shows Duplicate entry #1062 while i am not entering primary key插入表显示重复条目 #1062 而我没有输入主键
【发布时间】:2016-09-10 05:26:00
【问题描述】:

我正在尝试将一组数据输入到我的 Cycles Table 中, 表结构如下。

当我尝试将数据插入表中时。我收到如下错误。

 PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '65535' for key 'PRIMARY''

我的问题是我不想将值插入我的主键字段 id。那么为什么我会收到重复错误。在下面检查我的插入查询。

我相信当自动增量字段留空时,应该自行添加值。

当我手动检查天气记录退出时

 Select * from Cycles where id = 65535

var_dump($resutls) 显示空数组,count($resutls) 为零

【问题讨论】:

  • 直接在数据库中试一下,让我知道输出 select * from your_tablename where id =65535
  • 嗨@JYoThI 我试过了,当我 var_dump 它显示空数组时,当我count($resutls) 结果为零;
  • 使用查询显示您对表格的描述:desc Cycles
  • ` "Select * from Cycles where id = 65535";`
  • 请用纯文本替换所有截图。

标签: php mysql primary-key sql-insert mysql-error-1062


【解决方案1】:

谢谢大家

您的建议。

我发现了错误,我必须将表结构中的 id (smallint) 更改为 id (int(11))。

smallint 数据类型没有做任何增量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-01
    • 2020-10-07
    • 1970-01-01
    • 2011-11-11
    • 2012-07-23
    • 2013-09-30
    • 2015-04-26
    相关资源
    最近更新 更多