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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:26:58+00:00 2026-05-12T06:26:58+00:00

I asked this in the users group with no response so i thought I

  • 0

I asked this in the users group with no response so i thought I would try here.
I am trying to setup a custom manager to connect to another database
on the same server as my default mysql connection. I have tried
following the examples here and here but have had no luck. I get an empty tuple when returning
MyCustomModel.objects.all().

Here is what I have in manager.py

from django.db import models 
from django.db.backends.mysql.base import DatabaseWrapper 
from django.conf import settings 
class CustomManager(models.Manager): 
    """ 
    This Manager lets you set the DATABASE_NAME on a per-model basis. 
    """ 
    def __init__(self, database_name, *args, **kwargs): 
        models.Manager.__init__(self, *args, **kwargs) 
        self.database_name = database_name 
    def get_query_set(self): 
        qs = models.Manager.get_query_set(self) 
        qs.query.connection = self.get_db_wrapper() 
        return qs 
    def get_db_wrapper(self): 
        # Monkeypatch the settings file. This is not thread-safe! 
        old_db_name = settings.DATABASE_NAME 
        settings.DATABASE_NAME = self.database_name 
        wrapper = DatabaseWrapper() 
        wrapper._cursor(settings) 
        settings.DATABASE_NAME = old_db_name 
        return wrapper 

and here is what I have in models.py:

from django.db import models 
from myproject.myapp.manager import CustomManager 
class MyCustomModel(models.Model): 
    field1  = models.CharField(max_length=765) 
    attribute = models.CharField(max_length=765) 
    objects = CustomManager('custom_database_name') 
    class Meta: 
        abstract = True 

But if I run MyCustomModel.objects.all() I get an empty list.

I am pretty new at this stuff so I am not sure if this works with
1.0.2, I am going to look into the Manager code to see if I can figure
it out but I am just wondering if I am doing something wrong here.

UPDATE:
This now in Django trunk and will be part of the 1.2 release
http://docs.djangoproject.com/en/dev/topics/db/multi-db/

  • 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-12T06:26:58+00:00Added an answer on May 12, 2026 at 6:26 am

    You may want to speak to Alex Gaynor as he is adding MultiDB support and its pegged for possible release in Django 1.2. I’m sure he would appreciate feedback and input from those that are going to be using MultiDB. There is discussions about it in the django-developers mainling list. His MultiDB branch may even be useable, I’m not sure.

    Since I guess you probably can’t wait and if the MultiDB branch isn’t usable, here are your options.

    • Follow Eric Flows method, bearing in mind that its not supported and new released of Django may break it. Also, some comments suggest its already been broken. This is going to be hacky.
    • Your other option would be to use a totally different database access method for one of your databases. Perhaps SQLAlchemy for one and then Django ORM. I’m going by the guess that one is likely to be more Django centric and the other is a legacy database.

    To summarise. I think hacking MultiDB into Django is probably the wrong way to go unless your prepared to keep up with maintaining your hacks later on. Therefore I think another ORM or database access would give you the cleanest route as then you are not going out with supported features and at the end of the day, its all just Python.

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

Sidebar

Related Questions

I recently asked this question in the pyglet-users group, but got response, so I'm
This question has been asked here in one form or another but not quite
(I asked this question in another way , and got some interesting responses but
I asked this question before, Here however I think I presented the problem poorly,
I get asked this question a lot and I thought I'd solicit some input
I am trying to do something similar to what the user who asked this
I previously asked this question here: Stop user from using enter to pass a
I asked this question a while back but now I'm looking to implement an
I asked this Can I automate creating a .NET web application in IIS? a
I asked this question: Serial Port (rs232) in Mono for multiple platforms and this

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.