Index: db/backends/mysql/introspection.py
===================================================================
--- db/backends/mysql/introspection.py	(revisione 9082)
+++ db/backends/mysql/introspection.py	(copia locale)
@@ -5,6 +5,24 @@
 
 foreign_key_re = re.compile(r"\sCONSTRAINT `[^`]*` FOREIGN KEY \(`([^`]*)`\) REFERENCES `([^`]*)` \(`([^`]*)`\)")
 
+def visitDFS(g):
+  vertices_order =[]
+  def dfs(g):
+      seen = {}
+      def visit(g, v):
+
+          seen[v] = 1
+          for u in g[v]:
+              if u not in seen:
+                  visit(g, u)
+          vertices_order.append(v)
+
+      for v in g:
+          if v not in seen:
+              visit(g, v)
+  dfs(g)
+  return vertices_order
+
 class DatabaseIntrospection(BaseDatabaseIntrospection):
     data_types_reverse = {
         FIELD_TYPE.BLOB: 'TextField',
@@ -28,11 +46,28 @@
         FIELD_TYPE.VAR_STRING: 'CharField',
     }
 
+
     def get_table_list(self, cursor):
         "Returns a list of table names in the current database."
         cursor.execute("SHOW TABLES")
-        return [row[0] for row in cursor.fetchall()]
+        tables = cursor.fetchall()
+        cursor.execute("""
+                SELECT  referenced_table_name, table_name
+                FROM information_schema.key_column_usage
+                WHERE 
+                    table_schema = DATABASE()
+                    AND constraint_name LIKE %s
+                    AND referenced_column_name IS NOT NULL""", ['%fk%'])
+        list_adj ={}
+        listtables = cursor.fetchall()
+        for t in tables :
+          list_adj[str(t[0])] =[]
+        for row in listtables:
+          list_adj[str(row[1])].append(str(row[0]))
 
+        return  visitDFS(list_adj)
+
+
     def get_table_description(self, cursor, table_name):
         "Returns a description of the table, with the DB-API cursor.description interface."
         cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name))
