diff -urp --strip-trailing-cr ../drupal-6.x-dev/modules/system/system.install ./modules/system/system.install
--- ../drupal-6.x-dev/modules/system/system.install	2007-11-07 10:55:20.000000000 +0100
+++ ./modules/system/system.install	2007-11-08 00:02:03.000000000 +0100
@@ -3957,35 +3957,9 @@ function system_update_6019() {
 function system_update_6020() {
   $ret = array();
 
-  $schema['menu_router'] = array(
-    'fields' => array(
-      'path'             => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'load_functions'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'to_arg_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'access_callback'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'access_arguments' => array('type' => 'text', 'not null' => FALSE),
-      'page_callback'    => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'page_arguments'   => array('type' => 'text', 'not null' => FALSE),
-      'fit'              => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'number_parts'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'),
-      'tab_parent'       => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'tab_root'         => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'title'            => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'title_callback'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'title_arguments'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'type'             => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'block_callback'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'description'      => array('type' => 'text', 'not null' => TRUE),
-      'position'         => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'weight'           => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'file'             => array('type' => 'text', 'size' => 'medium')
-    ),
-    'indexes' => array(
-      'fit'        => array('fit'),
-      'tab_parent' => array('tab_parent')
-    ),
-    'primary key' => array('path'),
-  );
+  // Here used to be menu_router table creation. It was moved to update.php
+  // to avoid warnings if the menu system gets called early (such as in statistics
+  // module's hook_exit() ).
 
   $schema['menu_links'] = array(
     'fields' => array(
@@ -4023,10 +3997,8 @@ function system_update_6020() {
     ),
     'primary key' => array('mlid'),
   );
+  db_create_table($ret, 'menu_links', $schema['menu_links']);
 
-  foreach ($schema as $name => $table) {
-    db_create_table($ret, $name, $table);
-  }
   return $ret;
 }
 
diff -urp --strip-trailing-cr ../drupal-6.x-dev/update.php ./update.php
--- ../drupal-6.x-dev/update.php	2007-10-20 23:57:49.000000000 +0200
+++ ./update.php	2007-11-08 00:19:30.000000000 +0100
@@ -770,7 +770,6 @@ function update_fix_d6_requirements() {
       db_add_field($ret, 'locales_source', 'textgroup', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'));
       db_add_field($ret, 'locales_source', 'version', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'));
     }
-    variable_set('update_d6_requirements', TRUE);
 
     // Create the cache_block table. See system_update_6027() for more details.
     $schema['cache_block'] = array(
@@ -786,6 +785,47 @@ function update_fix_d6_requirements() {
       'primary key' => array('cid'),
     );
     db_create_table($ret, 'cache_block', $schema['cache_block']);
+
+    // Create the menu_router table. See system_update_6020() for more details.
+    $schema['menu_router'] = array(
+      'fields' => array(
+        'path'             => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'load_functions'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'to_arg_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'access_callback'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'access_arguments' => array('type' => 'text', 'not null' => FALSE),
+        'page_callback'    => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'page_arguments'   => array('type' => 'text', 'not null' => FALSE),
+        'fit'              => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+        'number_parts'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'),
+        'tab_parent'       => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'tab_root'         => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'title'            => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'title_callback'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'title_arguments'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'type'             => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+        'block_callback'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'description'      => array('type' => 'text', 'not null' => TRUE),
+        'position'         => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+        'weight'           => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+        'file'             => array('type' => 'text', 'size' => 'medium')
+      ),
+      'indexes' => array(
+        'fit'        => array('fit'),
+        'tab_parent' => array('tab_parent')
+      ),
+      'primary key' => array('path'),
+    );
+    db_create_table($ret, 'menu_router', $schema['menu_router']);
+
+    // Provide fake menu entry for the default path 'node', just
+    // for the time of update.php running.
+    $ret[] = update_sql("INSERT INTO {menu_router}
+      (path, fit, number_parts, tab_root, title, title_callback, type)
+      VALUES ('node', '1', '1', 'node', 'Drupal database update', 't', '16')");
+    variable_set('menu_masks', array(1));
+
+    variable_set('update_d6_requirements', TRUE);
   }
 
   return $ret;
