Skip to content

Instantly share code, notes, and snippets.

@CTimmerman
Last active March 7, 2016 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CTimmerman/8edaf32d6818f354a857 to your computer and use it in GitHub Desktop.
Save CTimmerman/8edaf32d6818f354a857 to your computer and use it in GitHub Desktop.
Change columns with constraints in MySQL.
show create table orders_products;
ALTER TABLE orders_products DROP FOREIGN KEY orders_products_ibfk_1;
alter table orders_products modify column orderId bigint;
alter table orders modify column id bigint AUTO_INCREMENT;
ALTER TABLE orders_products ADD CONSTRAINT `orders_products_ibfk_1` FOREIGN KEY (`orderId`) REFERENCES `orders` (`id`);
@CTimmerman
Copy link
Author

As disabling foreign key checks is dangerous and didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment