Adding zerofill to existing table

David Jones picture David Jones · Jun 25, 2012 · Viewed 8.1k times · Source

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

This is the error I get:

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.

Any help would be great!

Answer

Kermit picture Kermit · Jun 26, 2012

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.