Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:13:00+00:00 2026-06-15T16:13:00+00:00

I have multiple apps in my Django site: mainsite , blog and tutorials .

  • 0

I have multiple apps in my Django site: mainsite, blog and tutorials.

Can I use different databases (e.g. PostgreSQL, MySQL) in different Django apps?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:13:01+00:00Added an answer on June 15, 2026 at 4:13 pm

    Here is what you will have to do to get going.

    1. Update settings for databases that you want to use.

    settings.py

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/var/db/projectdb'
    }
    'db_app1': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/var/db/app1db'
    }
    'db_app2': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/var/db/app2db'
    }
    
    1. For each database, implement a database router that will route the queries appropriately. In your case implement in each app. Note this more or less taken from django docs.

    dbRouter.py (place in ‘app1’ folder):

    # DB router for app1
    class App1DBRouter(object):
            """
        A router to control db operations
        """
        route_app_labels = {'app1'}
        db_name = 'db_app1'
    
        def db_for_read(self, model, **hints):
            """
            Attempts to read auth and contenttypes models go to self.db_name.
            """
            if model._meta.app_label in self.route_app_labels:
                return self.db_name
            return None
    
        def db_for_write(self, model, **hints):
            """
            Attempts to write auth and contenttypes models go to self.db_name.
            """
            if model._meta.app_label in self.route_app_labels:
                return self.db_name
            return None
    
        def allow_relation(self, obj1, obj2, **hints):
            """
            Allow relations if a model in the auth or contenttypes apps is
            involved.
            """
            if (
                obj1._meta.app_label in self.route_app_labels or
                obj2._meta.app_label in self.route_app_labels
            ):
               return True
            return None
    
        def allow_migrate(self, db, app_label, model_name=None, **hints):
            """
            Make sure the auth and contenttypes apps only appear in the
            self.db_name database.
            """
            if app_label in self.route_app_labels:
                return db == self.db_name
            return None
    
    1. Update DATABASE_ROUTERS in settings.py

    settings.py

    DATABASE_ROUTERS = ['app1.dbRouter.App1DBRouter', 'app2.dbRouter.App2DBRouter']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project w/ multiple apps. I am attempting to use the dumpdata
I have multiple apps that use a shared set of files. I would like
I have a Django project that has multiple django apps. One of them has
If I'm an Apple Push Notification provider for multiple iOS apps can I use
I have multiple symfony2 applications which share common entities, but use different database settings.
Currently, we have multiple CakePHP instances on different domains sharing the same MySQL database.
I'm writing some apps that have multiple languages. I know I can set up
We have multiple MFC apps, which use CMutex( false, blah ), where blah allows
I have one library for multiple apps, all of these apps will be in
I have multiple but similar client-side iPhone apps, managed as branches in git (all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.