ALTER TABLE `mm_SponsorCategory` ADD `limit` INT NULL DEFAULT NULL AFTER `description`; ALTER TABLE `mm_SponsorCategory` CHANGE `limit` `limit` INT(11) UNSIGNED NULL DEFAULT NULL; ALTER TABLE `mm_SponsorshipSubmission` ADD `categoryId` INT UNSIGNED NULL DEFAULT NULL AFTER `categoryTitle`, ADD INDEX (`categoryId`) ; ALTER TABLE `mm_SponsorshipSubmission` ADD FOREIGN KEY (`categoryId`) REFERENCES `mm_SponsorCategory`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; UPDATE mm_SponsorshipSubmission as `ss` JOIN mm_CartItem as `ci` ON `ci`.`cartItemType` = 'Sponsor\\Category\\CartItem' AND `ci`.`productId` = `ss`.`id` SET `ss`.`categoryId` = `ci`.`productCategoryId` WHERE `ss`.`categoryId` IS NULL;