向现有表添加零填充 [英] Adding zerofill to existing table

查看:120
本文介绍了向现有表添加零填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将ZEROFILL添加到MySQL数据库中自动递增的主ID字段中.这是代码(由MySQL Workbench自动生成):

I'm trying to add ZEROFILL to an auto-incremented primary ID field in a MySQL database. Here is the code (auto-generated by MySQL Workbench):

ALTER TABLE `database`.`table` CHANGE COLUMN `id` `id` INT(11) ZEROFILL NOT NULL AUTO_INCREMENT

这是我得到的错误:

Error Code: 1025. Error on rename of './database/#sql-2c8_cb' to './database/table' (errno: 150)

似乎已经创建了一个临时表,并且在使用原始表名重命名该临时表时发生了错误.

It appears that a temp table has been created and when the error occurs when the temp table is renamed with the original table name.

任何帮助都会很棒!

推荐答案

如果使用InnoDB,请在执行更改后立即检查状态监视器(SHOW ENGINE INNODB STATUS).它应该告诉您是否是由于FK约束.您可能需要删除约束,更改列,然后再次创建它们.

If using InnoDB, check the status monitor (SHOW ENGINE INNODB STATUS) right after you execute the alter. It should tell you if it's because of the FK constraint. You may need to drop the constraints, alter the column and create them again.

这篇关于向现有表添加零填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆