Question

Can django use an external database? I mean, if you have one server for the db and other n-servers with the web server, can django use the db on an external machine? Can django do queries via internet to another django db?

Was it helpful?

Solution

Yes, your database and web server can be on separate servers. You just have to specify in your settings file the host. See https://docs.djangoproject.com/en/dev/ref/settings/#databases

OTHER TIPS

As the relevant documentation states, Django is capable of using multiple databases. Whether remote access is supported will depend on which one you choose to use - but, as a general rule, it is supported, with the notable exception of sqlite

Yes you can access the database from anywhere. But they(you) need to provide database privileges for your IP. some code is like,

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': Remote Host,
        'PORT': '5432',
    }
}

You can also use external django package https://github.com/kennethreitz/dj-database-url for deployment.

I reach this post, but in my case, I need to access another database. My intention is create an application that report informationa from another database. I needed to use two databases. I found the way in the django documentation.

https://docs.djangoproject.com/en/3.2/topics/db/multi-db/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top