Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch Django development server with a different database setting (not default)

i have different configurations for django database in settings, one named "default" and one named "clean".

How i can run the development server (python manage.py runserver ip:port) binding the "clean" database setting and not the default?

like image 674
apelliciari Avatar asked Jul 28 '12 14:07

apelliciari


People also ask

Can I use multiple database in Django?

Django's admin doesn't have any explicit support for multiple databases. If you want to provide an admin interface for a model on a database other than that specified by your router chain, you'll need to write custom ModelAdmin classes that will direct the admin to use a specific database for content.


2 Answers

You can hold 2 different settings.py and while run manage.py do : python manage.py runserver --settings=[projectname].[settingsfile].

change the settingsfile according to your database.

like image 108
Nuno_147 Avatar answered Sep 18 '22 19:09

Nuno_147


if DEBUG:
    DATABASES = {
        'clean': {
            'ENGINE': 'django.db.backends.',
            'NAME': '',
            'USER': '',
            'PASSWORD': '',
            'HOST': '',
            'PORT': '',
            },
        }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.',
            'NAME': '',
            'USER': '',
            'PASSWORD': '',
            'HOST': '',
            'PORT': '',
            },
        }
like image 40
Hedde van der Heide Avatar answered Sep 19 '22 19:09

Hedde van der Heide