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

  • SEARCH
  • Home
  • 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 4111738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:06:18+00:00 2026-05-20T22:06:18+00:00

With Django multidb, it’s fairly easy to write a router that runs a master/slave

  • 0

With Django multidb, it’s fairly easy to write a router that runs a master/slave infrastructure. But is it possible to write a router that writes to multiple databases? My use case is a collection of projects, all running on the same domain. To save users from registering/login in on every site, I’d like to synchronize the contrib.auth and contrib.sessions tables. Is that possible with Django multidb or should I look into replication features of the database system (MySQL in my case)?

  • 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-05-20T22:06:19+00:00Added an answer on May 20, 2026 at 10:06 pm

    I’m working on a Django sharding schema right now.

    i looked at the Django router but decided to roll my own.

    some thoughts on your issue:

    1. One idea is to use one database and then copy over the appropriate data via the use of Django signals on post-save.

    something like–

    import settings.databases as dbs_list
    
    def post_save_function(UserModel):
         for db in dbs_list:
              UserModel.save(using=db,force_insert=True)
    

    saving User objects (at least on a single-DB model) seems to save session, auth, etc. data under the hood via the various magic occurring inside django.contrib, so there’s a chance you might not have to go in and figure out the names and types of all these database tables.

    in support of the possibility of this working, I swear I read somewhere recently (probably on one of Alex Gaynor’s blog posts) that if an object has a foreign key Django will attempt to use the same DB the object lives on (for obvious reasons in light of the way Django typically operates).

    1. another idea:

    from the example on the Django multiDB page you referenced I wonder if something like the following would work:

    their sample code:

    def allow_syncdb(self, db, model):
            "Explicitly put all models on all databases."
            return True
    

    a possible modification:

    def allow_syncdb(self, db, model):

        if isinstance(model,User):
             return True
    
        elif isinstance(model,Session):
             return True
    
        else:
             ''' something appropriate --
                 whatever your sharding schema is for other objects '''
    

    looking at it again, this code would probably be more useful as the “db_for_write” function. but you get the idea.

    there are no doubt other types of model you would have to add to make this work (all the auth stuff, which is extensive).

    good luck! hope this is helpful in some way.

    i’m interested in your findings and comments!

    jb

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django project that I have been using for a while, but
Django's views documentation states that the default 500 view passes no variables to this
Django has a number of open source projects that tackle one of the framework's
Django-admin is pluralizing a model that I have running as a proxy class. The
Django newbie here I know that I can change the encoding of a table
Django 1.2 introduced a new template loader, that stores data in cache ( django.template.loaders.cached.Loader
Django-Social in its feature list claims that it supports associating multiple authentication providers to
Django query gives me below output format,but i want below format data=`[{'total': 1744, 'name:
Django's noob question: I use dango.contrib.auth for managing users of my site. But now,
sing django and jQuery I am trying to implement a button that, using the

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.