ALTER TABLE bs.waste ADD buyerFk int(10) unsigned NOT NULL; UPDATE bs.waste w JOIN account.`user` u ON u.name = w.buyer COLLATE utf8mb3_unicode_ci SET w.buyerFk = u.id; ALTER TABLE bs.waste DROP PRIMARY KEY, DROP COLUMN family, DROP COLUMN rate, DROP COLUMN buyer; ALTER TABLE bs.waste CHANGE buyerFk buyerFk int(10) unsigned NOT NULL AFTER `week`; ALTER TABLE bs.waste ADD CONSTRAINT waste_user_FK FOREIGN KEY (buyerFk) REFERENCES account.user(id) ON DELETE RESTRICT ON UPDATE RESTRICT; ALTER TABLE bs.waste ADD saleQuantity int(11) DEFAULT NULL NULL; ALTER TABLE bs.waste MODIFY COLUMN saleTotal decimal(10,2) DEFAULT NULL NULL; ALTER TABLE bs.waste MODIFY COLUMN saleWaste decimal(10,2) DEFAULT NULL NULL; ALTER TABLE bs.waste CHANGE saleWaste saleInternalWaste decimal(10,2) DEFAULT NULL NULL; ALTER TABLE bs.waste ADD saleExternalWaste decimal(10,2) DEFAULT NULL NULL; ALTER TABLE bs.waste CHANGE saleQuantity saleQuantity decimal(10,2) DEFAULT NULL NULL AFTER itemTypeFk; ALTER TABLE bs.waste CHANGE itemFk itemFk int(11) DEFAULT 0 NOT NULL AFTER itemTypeFk; ALTER TABLE bs.waste ADD CONSTRAINT waste_pk PRIMARY KEY (`year`, `week`, buyerFk, itemTypeFk, itemFk);