Home

Primary links

  • top o the deck
  • Drupal for Beginners
  • about
  • links
  • give me some sugar

Drupal stuff

  • EDAM
  • STARDOM
  • Question Bank
  • Drupal musings
  • Drupal tips
Home Blogs Drupalace's blog

Key stuff on this site

Easy Drupal Admin Manual (EDAM)

SEO, Traffic and Revenue: Drupalace's Online Manual (STARDOM)

Drupal for Beginners

Subscribe to posts by RSS or email

Subscribe to Drupal Ace by RSS feed RSS feed 

Subscribe to Drupal Ace by Email

Donate towards my web hosting bill! Get a great host!

Share and save

Share/Save

Random piece of content

Maintenance and Construction Notices

Manuals on this site

  • Easy Drupal Admin Manual (EDAM)
    • Welcome to Your Site
    • First Steps: Please Read!
      • Understanding These Instructions
      • Important Terminology!
      • Best Practices for Site Admins
    • Super Quick Guide (for the experienced and the brave)
    • Logging In
    • Your Administrator Tools
    • Setting Site Basics
      • Setting Site Information
      • Configuring Your Theme
    • Creating Content
      • Node Types
      • Create a Page Node
      • Create a Story Node
      • Create a Blog Entry Node
      • Making Images and Other Files Available
      • Using Text and Image Editors
    • Organizing Your Content
      • Terms, Vocabularies, and Taxonomy: "Tagging" Your Content
        • Taxonomy Suggestions
      • Menus, Links, and Paths: Navigating the Site
        • Content Paths and URLs
        • Creating Links
        • Working with Menus: Administration Form (Drupal 6)
        • Working with Menus: Administration Form (Drupal 5)
        • Creating Menu Items on the Fly
        • Placing Menus on Your Pages
      • Placing Content on pages
        • Creating a page from a Single Node
        • Creating a page from a List of Nodes
        • Setting the Front Page
      • Working with Blocks
    • Maintenance Stuff
      • Maintenance and Construction Notices
    • Other Fun Things
      • Changing Color of Garland Theme
      • Free Aliases!
  • SEO, Traffic and Revenue: Drupalace's Online Manual (STARDOM)
    • Set a Clear Goal
    • Make a Good Site
      • Put out the Welcome Mat
      • Make Great Content
      • Build a Great Brand
      • Make Navigation Easy
      • Tune Site Performance
    • Drive Traffic
      • Promote your Site
      • Get Found with SEO
    • Build a Community
      • Build an Offsite Community
    • Monitor and Improve
    • One-Page Checklist
    • Drupal and the Blogging Starter Checklist
      • Drupal and the Blogging Starter Checklist, Part 1
      • Drupal and the Blogging Starter Checklist, Part 2
      • Drupal and the Blogging Starter Checklist, Part 3
      • Drupal and the Blogging Starter Checklist, Part 4
      • Drupal and the Blogging Starter Checklist, Part 5
      • Drupal and the Blogging Starter Checklist, Part 6
      • Drupal and the Blogging Starter Checklist, Part 7

Recent comments

  • Deleting cookies

    Good point; thanks! Deleting cookies and/or caches, depending on the problem at hand, is a part...

  • It worked

    adding $GLOBALS['tempUser'] = $user; worked but I find it worth noting that I had to delete...

  • very good document...

    very good documentation for beginners!!!!!! thanks!!

  • del penitential 62

    strike out abject
    eliminate penitent 5

  • Chat

    Thank you a lot about very beneficial to my work was very useful thank you

more

Manhandle that database back into shape

Submitted by Drupalace on Mon, 2009-08-31 00:51
  • modules
  • trouble
Come here, database

A short tale of how I got the links page working after a Weblinks module upgrade broke it.

The ideal solution would be to track down the exact problem, posting issues and working with the module's maintainers, finally squaring everything away with the current module version. However, the issues page doesn't show anyone else having trouble with the module; the problem may be an obscure glitch related to my frequent abuse of this site for experimentation purposes. More importantly, at the moment I'm short on time to fiddle with this. I decided I'd just go back to the previous version of the module and be done with it.

Here's the process, including an unexpected problem necessitating light database vivisection:

Getting ready

I had one other site (Site B) using Weblinks and running off the same Drupal 6 installation. Not surprisingly, its weblinks stopped working properly when I updated the module but didn't run update.php. I avoided that update for obvious reasons (it had left Drupalace.com's weblinks broken).

It would have been interesting to run update.php on Site B and see whether Weblinks broke there too, but that site isn't meant as a punching bag like this one, and I really just wanted a quick fix for Drupalace.com via a module downgrade. 

Fortunately, back when I installed Weblinks 6.x-2.1, I didn't trash the old module; I moved it to a directory named "uninstalled modules". So it was readily available for the downgrade process. This is good practice for any module upgrade: Keep the old version, in case you need to quickly jump back. 

Diving in

The steps I took, for the possible edification of other beginners at poking database innards:

1. Back up the site's database (or in this case, both sites'). Really important.

2. Inside the Drupal installation, replace Weblinks 6.x-2.1 with the previous version I had used, 6.x-1.5. 

3. Check the weblinks page on Site B. With its un-updated database, it should revert to proper behavior now that the previous module is back in place... Yep, its weblinks are back in action. Good!

4. For kicks, see whether weblinks now work on Drupalace... No. Its updated database recoils from the old module, spewing error messages. Here's a taste:

user warning: Unknown column 'bw.weight' in 'field list' query: SELECT DISTINCT(n.nid), bw.weight, n.title FROM node n INNER JOIN node_revisions nr ON nr.vid = n.vid INNER JOIN weblinks bw ON bw.vid = nr.vid LEFT JOIN term_node tn ON tn.nid=n.nid AND tn.vid=n.vid WHERE n.status = 1 AND tn.tid IN (116) ORDER BY bw.weight ASC, n.title ASC in /xxxxx/sites/all/modules/weblinks/weblinks.module on line 1142.

5. For further giggles, run update.php on Drupalace and see what happens. Just a bunch of errors like

FAILED: ALTER TABLE {weblinks} DROP tid

No surprise there; you generally expect update.php to do good stuff when upgrading, not downgrading, modules. 

6. Time to guess where the damage is. From clues like the above, it's pretty likely that the culprit is the weblinks table in the database. Simple plan of attack: Nuke existing weblinks table, import weblinks table from old (pre-Weblinks 6.x-2.1) backup of database. Drink beer. 

However:

7. Head to phpMyAdmin. Try to import old database backup into a new empty database, so I can export just its weblinks table for subsequent import into Drupalace. But... despite many attempts, phpMyAdmin only runs forever without importing the database. Possibly a temporary issue with the hosting service. Something to look into soon. Right now, I want to finish this fix somehow.

8. Isn't there a way to pluck out and import just the weblinks table from the saved database backup, rather than try to import the whole database backup? There probably is, if I start searching and asking. But I've got short time to play with this and want a fast fix, dagnabbit... 

9. I check the contents of Drupalace's wayward weblinks table, which looks like this:

Peeking inside (via the 'Browse' tab), things appear sound, in that each record has values in the nid and vid fields, proper URLS in the url field, and so on. So maybe if I just find whatever changes Weblinks 6.x-2.1 has made, and manually set them back to their 6.x-1.5 status, I'll rescue the site. And then drink beer. Sounds like a plan.

10. I compare the above table with the law-abiding weblinks table from Site B's database. That looks like this:

Sure enough, there are differences. For one, Weblinks 6.x-2.1 clearly added several new fields, like urlhash and last_status_info. But new fields shouldn't cause trouble for the old module, so I won't worry about them for now. More importantly, Drupalace's updated table had lost a field, weight. And a couple other fields common to both tables showed changes in their Type, Attributes, Null, or Default values.

11. Fumbling with phpMyAdmin, I add a weight field to Drupalace's weblinks table. (It doesn't sound like a vital field to me, but I'm not making judgment calls today.) Then I change values in Drupalace's table (using the little 'Change' pencil icon) so they match those in Site B's table. For example, I change Type of the last_click field from the newfangled datetime to the comfortable old int(10). 

Note that (for me) this isn't a process of necessarily understanding these table values. The mental workings aren't running much deeper than "do whatever makes the Drupalace table look like the Site B table. Yeah, that's it." (This, not Shakespeare, is what you get when you set a monkey before a keyboard.) 

Finishing the changes, Drupalace's table now looks like this (still leaving in extraneous new fields for now):

12. Final step: See whether Drupalace's weblinks page now works like it should. It does. As expected.

That's it. It's all piddling stuff to the pros, who could perform (and explain) the procedures with much more ease. Or who would have an even better method to fix things. Or who wouldn't have run into trouble with the module update in the first place.

But as a user who still tends to shy away from the deep innards, even mild hackwork like the above makes me feel like I've picked up a hickory club and gone all Buford Pusser on that database. It's heady stuff. The point for beginners is: With minimal knowledge of database tools like phpMyAdmin, and a site you're willing to hack, and diligent backups, you can poke around a database and learn to cobble some handy fixes. 

Now step aside. I'm still carrying the hickory club, and I want that beer. 

Share/Save
  • Drupalace's blog
  • Printer-friendly version
  • Quote

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><br><p>
  • You may quote other posts using [quote] tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options


Relevant Content

The Drupal Ace logo has dealt these content suggestions from the deck.

  • Back on track with Node Import
  • Module upgrades cause troubles
  • Read More link troubles fixed?
  • Testing Ubercart ecommerce: Please help with missing tabs!
  • Checking out Amazon on Drupal 6, Part 2
  • Checking out Amazon on Drupal 6, Part 1
  • Great Modules for the Drupal Beginner

Learn Drupal, hands-on

Get the beginner-friendly ebook that teaches community site building via a live case study.

Drupal 6 Ultimate Community Site Guide

Read the review

Drupal mini tip

The Book module creates "Printer-friendly version" at the bottom of Book pages. If you hit that link from a page with child pages, Drupal creates a printer-friendly page from that page and its child pages. If you hit the link from the Book's top page, you get the whole book in a single page!

It's a deal!

Dreamhost dealsDrupal Ace presides over his domain, proudly ensconced in his DreamHost eyrie. Won't you join me?

Promo code deal!

Just enter the code 49ER when you register for an account, and save $49 off the already-low price. No strings!

Read my hosting service review

Powered by Drupal, an open source content management system

Copyright 2007 and forever after. Made with Drupal, of course. On OS X, of course. Served up by DreamHost. DreamHost

RoopleTheme