#12661 closed (wontfix)
Support setting a "default" database
Reported by: | Kyle Fuller | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have wrote two patches which allow you to select a "default" database, one is for a settings variable, another is a environmental variable. While I was playing around with multidb I found it annoying that I couldn't set a default db, I wanted to be able to use the same settings.py on my site for development and my production site.
environ.diff
os.environ['DJANGO_DEFAULT_DB'] = "development"
This could be set in your wsgi file.
settings.diff
DEFAULT_DB_ALIAS = "development"
This would go into settings.py
Attachments (2)
Change History (6)
by , 15 years ago
Attachment: | environ.diff added |
---|
by , 15 years ago
Attachment: | settings.diff added |
---|
comment:1 by , 15 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 15 years ago
russellm, it doesn't quite allow it. Your default database still needs to work. I don't have MySQLdb on my development system, but that should not matter, I want to use a development database.
$ ./manage.py syncdb --database=development django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb $ cat settings.py | head -n 26 | tail -n 2 'development': { 'ENGINE': 'django.db.backends.sqlite3',
If I was to do the same thing with a db router to make it use 'development' it would still fail because it is trying to load the 'default' database.
comment:3 by , 15 years ago
I'm still not convinced. Even without using a router, you can solve this problem.
You've already said you're willing to accept an environment variable to control this. So why not just have three settings files - a common settings, production settings and development settings, and use DJANGO_SETTINGS_MODULE to switch between them.
If, for some reason, you don't want to use DJANGO_SETTINGS MODULE, you could still put the following in your settings:
import os if os.environ.get('DJANGO_DEFAULT_DB'): DATABASES = {...} else: DATABASES = {...}
I don't see the advantage in introducing a new environment variable to allow the specific configuration pattern you describe.
comment:4 by , 15 years ago
Hmm, ok, I think I will go with the if statement inside my settings module. I think I mis-understood what multidb support was for. Thanks for clearing this up.
You've been beaten to the punch by about 10 minutes :-)
[12272] introduced a way to define database routers, which can be used to solve the problem you describe.