USE vn; ALTER TABLE vn.itemType MODIFY COLUMN id smallint(5) unsigned NOT NULL; -- id drop references ALTER TABLE vn.item DROP FOREIGN KEY item_ibfk_5; ALTER TABLE vn.itemTypeRestriction DROP FOREIGN KEY itemTypeRestriction_itemType_id_fk; ALTER TABLE vn.itemTypeTag DROP FOREIGN KEY itemTypeTagTipos; ALTER TABLE vn.zoneFilter DROP FOREIGN KEY zoneFilter_FK_1; -- code drop references ALTER TABLE vn.clientItemType DROP FOREIGN KEY clientItemType_FK_1; -- drop and add constraint ALTER TABLE vn.itemType DROP PRIMARY KEY; ALTER TABLE vn.itemType ADD CONSTRAINT itemType_PK PRIMARY KEY (id); ALTER TABLE vn.itemType DROP KEY tipo_id_UNIQUE; ALTER TABLE vn.itemType ADD CONSTRAINT itemType_UN UNIQUE KEY (code); -- code add references ALTER TABLE vn.clientItemType ADD CONSTRAINT clientItemType_FK_1 FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(code); -- id add references ALTER TABLE vn.item ADD CONSTRAINT item_FK_1 FOREIGN KEY (typeFk) REFERENCES vn.itemType(id); ALTER TABLE vn.itemTypeRestriction ADD CONSTRAINT itemTypeRestriction_FK FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id); ALTER TABLE vn.itemTypeTag ADD CONSTRAINT itemTypeTag_FK FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id); ALTER TABLE vn.zoneFilter ADD CONSTRAINT zoneFilter_FK_1 FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id);