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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:39:30+00:00 2026-05-26T03:39:30+00:00

Is it possible to add a new database connection to Django on the fly?

  • 0

Is it possible to add a new database connection to Django on the fly?

I have an application that uses multiple databases (django 1.2.1), and while running, it’s allowed to create new databases. I’d need to use this new database right away (django.db.connections[db_alias]). Is it possible without server restart? Using module reload here and there?

Thank you for your time.

  • 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-26T03:39:30+00:00Added an answer on May 26, 2026 at 3:39 am

    It is possible… but not recommended…
    You can access the current connection handler…

    Use something like this:

    from django.db import connections
    if not alias in connections.databases:
        connections.databases[alias] = connections.databases['default']  # Copy 'default'
        connections.databases[alias]['NAME'] = alias              
    

    Make sure you do not attempt to add a new alias to the databases dictionary while there is ANY database activity on the current thread.

    An issue you need to overcome, is that this code will need to be placed somewhere were it will always be touched by the current thread before trying to access the database. I use middleware to achieve this.

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

Sidebar

Related Questions

Would it be possible to add a new operator to the String class that
I currently have a connection class that handles all of my database connectivity. What
Is it possible to add new codec's to ffmepg? i searched a bit and
I'm wondering if its possible to add new class data members at run-time in
Is it possible to both alter a column and add a new column in
Is it possible to add an image overlay to a google map that scales
Is it possible to add a jQuery function so that a click in a
I have an application built upon ASP.NET 3.5 and PostgreSQL 8.3. My database has
Our application uses H2Sharp to access a H2 database from C# (Framework v4). Recently
I have a project that uses MVC 3 and Entity Franework. The site works

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.