Last active
December 29, 2015 13:29
-
-
Save akovalyov/7677179 to your computer and use it in GitHub Desktop.
get all constraints from mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- helps to debug strange errors like General error: 1005 Can't create table '$some_db.#sql-186d_71' (errno: 121) | |
-- usually it happens whem you manually rename a table and schema is generated via a tool | |
-- need to execute also | |
-- ALTER TABLE `$table` | |
-- DROP FOREIGN KEY `old_key`, | |
-- ADD CONSTRAINT `new_key` FOREIGN KEY (field) REFERENCES $table2(id); | |
SELECT | |
constraint_name, | |
table_name | |
FROM | |
information_schema.table_constraints | |
WHERE | |
constraint_type = 'FOREIGN KEY' | |
AND table_schema = DATABASE() | |
ORDER BY | |
constraint_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment