Skip to content


DBAL-34: MySql getListTableForeignKeysSQL doesn't work for 5.0.xx #1526

doctrinebot opened this Issue · 4 comments

2 participants


Jira issue originally created by user tiw:

The sql contains mysql specific code. And for the mysql the sql statement has syntax error.

in /Doctrine/DBAL/Platforms/MySqlPlatform.php:
public function getListTableForeignKeysSQL($table, $database = null)
"k.REFERENCED*COLUMN_NAME /!50116 , c.update_rule, c.deleterule / ".
"FROM information
schema.key_columnusage k /!50116 ".
"INNER JOIN informationschema.referentialconstraints c ON ".
" c.constraintname = k.constraintname AND ".
" c.tablename = '$table' */ WHERE k.tablename = '$table'";

    if ($database) {
        $sql .= " AND k.table*schema = '$database' AND c.constraint*schema = '$database'";

    $sql .= " AND `REFERENCED*COLUMN*NAME` is not NULL";

    return $sql;


For the mysql lower as 5.1.16 the SQL could be as the following:

SELECT DISTINCT k.CONSTRAINT*NAME, k.COLUMN_NAME, k.REFERENCED_TABLE_NAME, k.REFERENCED_COLUMN_NAME FROM information_schema.key_column_usage k WHERE k.table_name = 'some_table' AND k.table_schema = 'some database' AND c.constraint_schema = 'some database' AND REFERENCED_COLUMN*NAME is not NULL

In this statement there is no reference of c


Comment created by @beberlei:



Issue was closed with resolution "Fixed"


Comment created by gedrox:

Pity that because of this the Doctrine schema-tool update action reports incorrect change list.
It tries to drop/add foreign keys because "ON DELETE CASCADE" option isn't read from the database at all.


Comment created by @beberlei:

5.0.x has no way to export the CASCADE details. Its just not possible to get this data in 5.0

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0.0-BETA3 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.