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 9043255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:41:42+00:00 2026-06-16T10:41:42+00:00

I have one database that I specifically using for Django. I ran into a

  • 0

I have one database that I specifically using for Django. I ran into a simple problem. For the user authentication in the login I need to use data from another database(mysql) and table. Both the tables are in the same server. How can I do that? Thanks

  • 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-16T10:41:43+00:00Added an answer on June 16, 2026 at 10:41 am

    You need to define both the databases in your settings.py. You should read through setting up multiple databases documentation. It’s pretty straight forward. Once you have databases configured and synchronized, you can manually select a database for a QuerySet as follows:

    Model.objects.using('database').all()
    

    Update:

    To specify a connection for a model you can define a Router as follows.

    from django.db import connections
    
    class MyRouter(object):
        """
        This router object will take care of the database
        operations for models.
        """
    
        def db_for_read(self, model, **hints):
            if hasattr(model,'connection_name'):
                return model.connection_name
            return None
    
        def db_for_write(self, model, **hints):
            if hasattr(model,'connection_name'):
                return model.connection_name
            return None
    
        def allow_syncdb(self, db, model):
            if hasattr(model,'connection_name'):
                return model.connection_name == db
            return db == default
    

    and then for your models in models.py you can do something like this:

    class MyModel(models.Model):
        connection_name="filename"
    

    Update#2

    you can setup the router anywhere you like. All you need to do is pass the Routers path to the DATABASE_ROUTERS variable in the settings.py file. For the sake of cleanliness of code and being organised i generally do this in a separate routers.py file under my application folder and then set the DATABASE_ROUTERS

    example:

    DATABASE_ROUTERS = ['myapp.routers.MyRouter',]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large script that has no database connection yet. I need one
i have one database, and it contains some columns. My requirement is that how
I have a website that has one database I have also Desktop apps that
I have a ms access database that has one table for each photo album
I have a table in database that is having some fields one of which
I have an Oracle database that I am connecting to with PHP OCI8. One
I have a rails 3.2 app that uses 2 databases. One database is the
With my database upgrade scripts, I typically just have one long script that makes
I have a database in one activity that I want to open in another
I have a database named contacts.db with a table named TABLE_NAME that has one

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.