My site has lost it's list of Books at ../admin/content/book/list. My content list still displays all the book pages, but the child pages have lost their parents in the outlines. When I try to edit the book pages to re-establish the outline, or reassign a book page to a new parent, I get a user warning:
"user warning: Duplicate entry '264' for key 2 query: INSERT INTO book (nid, mlid, bid) VALUES (264, 3763, 325) in /home/content/b/c/h/bchccnet/html/drupal/modules/book/book.module on line 466."
I have checked the node and book tables, and the data is still there. Anyone have any idea how I can bring back the books and their structures? Previous to this problem I did remove some unused modules and ran an update.php.
Any help is greatly appreciated.

Comments

cneesen’s picture

just to add to the above problem. I also lost some menu links for my content at the same time.

optidel’s picture

Same thing happened to me too. I lost all my book lists. All the content are there. Just not able to access the hierarchy. Not able to add page to a new book either.

cneesen’s picture

After some research, I found that the book navigation is linked to the menu in Drupal 6. I had uninstalled some content access modules and got a warning that content tied to these modules would be deleted, but clicked ok anyway. Big mistake. After that, the parent book pages lost their structure, and any attempt to re-establish the book or relink the pages gave me a duplicate entry error. Apparently I lost the connection between the node table and the book table in the database. My solution was to clear the book table of data, and recreate the parent book pages, then one by one relink the child pages to the parent. I still have a problem with the book navigation block not showing the book structure on some of the books--I think this is related to having the parent page be a 'newer' node than the child page.
I hope this helps you..I've learned not to uninstall a module. Good luck with your site.

px’s picture

Ok, had the same experience with all books all of a sudden being lost. I could create new books, using new nodes, but no luck with putting old nodes back into their original outline (always resulted in that SQL warning about duplicate rows).

Unfortunately, I noticed the broken books 3 days late and did a lot of administration stuff in that timeframe, so I cannot really say, what caused the trouble. I also had ACL and Forum Access uninstalled, but these two modules don't seem to be the culprits (at least nothing broke, when I did an uninstall of these modules on the test server and the uninstall scripts do not appear to touch the tables in question).

My instructions for damage repair:
First of all, the book table only states which nodes belong to the same book. The actual hierarchy is provided by the menu_links table. Make sure to back up both tables before trying to fix anything.

The book table needs to be cleared first. This can be done with a DELETE FROM book; query. Afterwards, all dangling references must be removed from the menu_links table. If that is omitted, the restored books may end up having multiple root nodes, causing the navigation block to fail to build up it's content area and thus not showing. In essence, every book is actually just a menu, by the name of book-toc-XXX (with XXX being the node id of the root node). Clear all book menus by using a query like delete from menu_links where menu_name like "book%"; (be careful with that! Do a select first to make sure, that you do not have any other menus, starting with "book").

Afterwards, the books have to be rebuild from hand, using the Book outline.

Hope, that helps.

px’s picture

!#@& it seems to have happened again! I'm still not sure, what caused it this time. Among other things (installing Notification & Messaging API) I did some rearranging of the navigation menu via Panels, though. That seems to be the most likely candidate.
Edit: Wrong again. The links were already broken in tonight's backup, before I did the rearranging.

optidel’s picture

Someone else has done some further research on this issue - http://davidherron.com/content/repairing-book-navigation-drupal-site

David has only described what has happened and the solution is pretty tough to implement. We still have to find out why and fix the code.

optidel’s picture

Is there an issue queue only for the books module? Within a day this issue has moved to the 8th page in the "Post Installation" forum.

haggai_e’s picture

I'm trying to upgrade from drupal 5 to drupal 6, and I've encountered the same issue. I don't remember uninstalling any module that would cause this. Could you explain how to repair this error. (I think recreating the book outline by hand would be fine, since I only had about a dozen of pages there.)

vrteach’s picture

We had our book hierarchy disappear sometime recently, exactly as is describe in the initial post here. It was probably coincident with my disabling some modules that I had hanging around from testing. But I unfortunately don't remember what I had removed.

After reading through these posts, I cleaned out the book table, and removed the book*toc entries from the menu_links table. Luckily we only had one book, with about six entries.

HorsePunchKid’s picture

There might be some help at #645214: No menu links, no books.

dkane’s picture

I had the same problem after doing some housekeeping and cleaning out some unused content access modules. While I'm not sure why it happened, but thankfully applying a variation on the solution provided at http://davidherron.com/content/repairing-book-navigation-drupal-site I was able to re-link my books without having to re-create them - which would have presented a real problem since I have node-specific access granted to many users based on triggered rules. Suffice to say it would have been a nightmare. The issue seemed to stem from a problem with the mlid (menu-link id) so what you have to do is get the mlid in the book table and menu_links table to agree, but first I had to let the parent node of the book know that it was a book (even though I'm not sure why it ceased to "know" in the first place). I implemented my solution in phpmyadmin which made it easier than doing all of this via straight SQL queries:

1. Browse to the parent node and click on "outline". In my case no book showed up, so choose "create new book" . This will return an error saying that the book already exists in the book table, but we're looking to create a new entry in the menu_links table, so you can ignore this error.

2. Open the menu_links and book tables in phpmyadmin in separate tabs for ease of switching. Then filter the menu_links table to show only books (WHERE module = 'book') and arrange them by mlid so that the newest table entries would show up on top. You will see a new table row for the "new" book you just added with a new mlid for that entry.

3. Find that node in the book table. I reccomend sorting by bid (book id) which is the same as the parent nid. This way you can quickly see all of the nodes that should belong to the book and knock it out quicker. Find the parent node you just created a new entry for in the menu_links table in the book table (for the parent node the nid will be the same as the bid) , and copy the new mlid from the menu_links table into the record for that node in the book table. Once you do this the book will once again let you add child nodes etc.

4. Now comes the truly annoying part. Go to the child nodes for your re-established book and re-associate them (via the outline tab) with your book. This will create new mlids in the menu_links table (and give you the same error about duplicate entries in the book table). Copy the new mlid for each child node and paste it in that node's row in the book table. As you do this these child nodes will be added back into the book with all of their navigational glory.

From there its just lather, rinse, repeat. I'm sure there is a better way to automate this via SQL, but since I'm not an SQL guru and didn't have THAT many disconnected nodes (only about 25 or so) it was just quicker, and less risky, for me to do it this way.

I hope this helps someone! I know how frustrating, and bewildering, this can be.

Thanks to maragnis and everyone on this thread for leading me to this functional, although certainly less than simple, solution!

joel_guesclin’s picture

If anyone could point me to a detailed explanation of how book structure works I would be grateful - I have this problem also but with 1000s of nodes in books, so doing it by hand is not really an option!

joel_guesclin’s picture

Having just gone through a bit of a heart-stopper, I conclude that the key is BACKUPS.
For a reason I have been unable to determine, the whole book structure disappeared. Clearly, this is to do with a corruption in the book and menu_links tables.
After much messing around, I went back to a previous backup and exported the contents of the backup's book and menu_links tables.
I then emptied ('TRUNCATE') the book and menu_links tables in the corrupted database, and imported the older versions.
This done, I only had the content since the backup still "hanging" outside the book structure, and it was straightforward enough to go through all this content and reattach it by the standard Drupal mechanisms.