Archive for June 2013

regexp: ADD CONSTRAINT to DROP FOREIGN KEY

if you have something like

ALTER TABLE `accounts_purchases`
  ADD CONSTRAINT `accounts_purchases_account` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `accounts_purchases_item` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;

and you are about to update those constraints:
You have to drop them first, by getting all their “symbols”…

here is a “simple” regexp to modify SQL export to DROPs Read more