From 5874952a8e799783c16e87e427fc13272f581843 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 19 Jul 2005 19:04:12 +0000 Subject: [PATCH] Improved error message when DATABASE_ENGINE is invalid. It now displays a list of all available database backends git-svn-id: http://code.djangoproject.com/svn/django/trunk@215 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/db/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/django/core/db/__init__.py b/django/core/db/__init__.py index 17e3d2a7fd..6b104ac161 100644 --- a/django/core/db/__init__.py +++ b/django/core/db/__init__.py @@ -18,8 +18,15 @@ from django.conf.settings import DATABASE_ENGINE try: dbmod = __import__('django.core.db.backends.%s' % DATABASE_ENGINE, '', '', ['']) except ImportError: + # The database backend wasn't found. Display a helpful error message + # listing all possible database backends. from django.core.exceptions import ImproperlyConfigured - raise ImproperlyConfigured, "Your DATABASE_ENGINE setting, %r, is invalid. Is it spelled correctly?" % DATABASE_ENGINE + import os + backend_dir = os.path.join(__path__[0], 'backends') + available_backends = [f[:-3] for f in os.listdir(backend_dir) if f.endswith('.py') and not f.startswith('__init__')] + available_backends.sort() + raise ImproperlyConfigured, "Your DATABASE_ENGINE setting, %r, is invalid. Is it spelled correctly? Available options are: %s" % \ + (DATABASE_ENGINE, ', '.join(map(repr, available_backends))) DatabaseError = dbmod.DatabaseError db = dbmod.DatabaseWrapper()