MySQL 停止自动增量?
我正在编写一个脚本,遗憾的是我继承了它——没有任何评论或任何东西。 啊! 出于测试目的,我复制了数据库中具有自动递增 ID 的表之一。 然而,当数据保存到数据库时,ID 号只是读取“0”——这是该列的默认值。 我不知道为什么它不再自动增加......有什么想法吗? 谢谢你!
I'm working on a script that sadly I inherited - with no commenting or anything. Argh!
For testing purposes I duplicated one of the tables in the database which had an auto-incrementing ID. When the data is saved to the database, though, the ID number just reads "0" -- which is the default for that column. I'm not sure why it's not auto increasing anymore... any thoughts? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确定将重复表中的字段设置为自动增量吗? 尝试运行:
看看它是否已设置。
Are you sure you set the field in the duplicate table to auto-increment? Try running:
And see if it is set or not.
您是从头开始创建新表还是作为真实副本创建? 如果该列应该自动递增,那么它应该是主键(或至少是唯一键),没有默认值。
Did you create the new table from scratch or as a real copy? If the column is supposed to auto increment it should be a primary (or at least a unique) key, with no default value.
只是为了仔细检查使用 sql 语句来显示 show为两个表创建表语法并进行比较。
Just to double check use the sql statement to show the show create table syntax for both tables and compare.
听起来您的列实际上不再是
auto_increment
了。 这种情况在我身上发生过几次,因为我用来创建备份的 phpMyAdmin 中有一个错误(?):它不会将auto_increment
关键字添加到 CREATE TABLE 语句中。 那真是屁股上的巨大疼痛......It sounds like your column isn't actually
auto_increment
any more. This has happened to me a couple of times because there was a bug (?) in phpMyAdmin which I used to create backups: it wouldn't add theauto_increment
keyword into the CREATE TABLE statements. That was a massive pain in the butt...