gpt4 book ai didi

mysql - phpmyadmin : Din't get auto_increment property on primary key after importing database

转载 作者:行者123 更新时间:2023-11-29 15:43:33 25 4
gpt4 key购买 nike

我在 phpmyadmin 中导入了数据库。
这是一个接近990MB的大型数据库。
但导入后出现问题。
所有的键约束都在那里,但主键没有设置为自动增量。
因此,当我在表中插入数据时,它会抛出重复条目和主键违规错误。

1062 - Duplicate entry '0' for key 'PRIMARY'

很明显,因为它会插入 0,以防未设置 auto_increment

我尝试通过运行
来重置 AUTO_INCRMENTALTER TABLE 用户 AUTO_INCRMENT=1001;
然后尝试检查 id 字段中的 auto_increment 但它给了我这个错误

Query error: 1062 - ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '1' for key 'PRIMARY'

最佳答案

你可以试试

  1. 检查索引和主键

  2. 删除索引和主键

更改表`用户`删除主键

  • 添加自动增量并添加主键
  • ALTER TABLE 表名 AUTO_INCRMENT = 1

    对于 InnoDB,您不能将 auto_increment 值设置为低于或等于当前最高索引。

    Note that you cannot reset the counter to a value less than or equal to >any that have already been used. For MyISAM, if the value is less than or >equal to the maximum value currently in the AUTO_INCREMENT column, the >value is reset to the current maximum plus one. For InnoDB, if the value >is less than the current maximum value in the column, no error occurs and >the current sequence value is not changed.

    所以,我们可以

    ALTER TABLE `users` ADD `id` INT( 11 ) NOT NULL PRIMARY KEY AUTO_INCRMENT FIRST

    希望它对你有用。

    关于mysql - phpmyadmin : Din't get auto_increment property on primary key after importing database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57321921/

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