Fixes #346. Multiple databases support in management commands.

Yes, right. My bad - just copied quickly from another script :/