#1390 Export tables list must be ordered by constraints

open
nobody
Normal
2015-06-24
2012-10-05
Serge
No

If so no need "disable foreign key checks" on export.

<?php
$query=mysql_list_tables($db,$dbid);
for($i=0;$i<mysql_num_rows($query);$i++)
$tables[current(mysql_fetch_row($query))]=0;
mysql_free_result($query);

$query=mysql_query("
SELECT `REFERENCED_TABLE_NAME`,`TABLE_NAME`
FROM `$schema`.`KEY_COLUMN_USAGE`
WHERE `TABLE_SCHEMA` = '$db' AND `REFERENCED_TABLE_SCHEMA` IS NOT NULL AND `TABLE_NAME` <> `REFERENCED_TABLE_NAME`
ORDER BY `REFERENCED_TABLE_NAME`
",$dbid);
for($i=0;$i<mysql_num_rows($query);$i++)
$constraints[current($t=mysql_fetch_assoc($query))][]=next($t);
mysql_free_result($query);

$again=true;
while($again)
if(!$again=false)
foreach($constraints as $table=>$rel)
foreach($rel as $t)
if(($tables[$table]<=$tables[$t])&&($tables[$table]++)&&($again=true))
break;
asort($tables);
$i=0;
foreach($tables as $k=>$v)$tables[$k]=$i++;unset($k);unset($v);unset($i);
$tables=array_flip($tables);

mysql_close($dbid);
?>

Discussion

  • Serge
    Serge
    2012-10-05

    $tables ordered for deleting
    for create and update in reverse order

     
  • Marc Delisle
    Marc Delisle
    2015-02-15

    • Priority: 5 --> Normal
     
  • As of now phpMyAdmin add constraints at the very end of export. So I do not see a requirement to order tables by their constraints.