SELECT i.TABLE_NAME as 'Table Name', k.COLUMN_NAME as 'Foreign Key', k.REFERENCED_TABLE_NAME as 'Primary Table', k.REFERENCED_COLUMN_NAME as 'Primary Key', i.CONSTRAINT_NAME as 'Constraint Name', 'Delete' as 'Delete' FROM information_schema.TABLE_CONSTRAINTS i LEFT JOIN information_schema.KEY_COLUMN_USAGE k ON i.CONSTRAINT_NAME = k.CONSTRAINT_NAME WHERE i.CONSTRAINT_TYPE = 'FOREIGN KEY' AND i.TABLE_SCHEMA = DATABASE()
Given the following schema
The generated query on relations.php will be:
It displays the relation twice:
I'm working on it.