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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:47:21+00:00 2026-06-16T16:47:21+00:00

I have configured database properly. If I want to access the data from the

  • 0

I have configured database properly. If I want to access the data from the table hello in the database called genes. What’s the proper way to do it? I can’t do from books.models import hello as I don’t have hello in models.py. The database genes and table hello is not the default Django database. I have two databases. I have already setup Router. I want to now access data. 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-16T16:47:22+00:00Added an answer on June 16, 2026 at 4:47 pm

    You need to do a few things..

    settings.py

    DATABASES = {
        'genes': {
            'ENGINE':   'django.db.backends.mysql',
            'NAME':     'genes',
            'USER':     'root',
            'PASSWORD': 'root',
            'HOST':     'localhost',
            'PORT':     '3360',
        },
        'default': {
            'ENGINE':   'django.db.backends.mysql',
            'NAME':     'django',
            'USER':     'root',
            'PASSWORD': 'root',
            'HOST':     'localhost',
            'PORT':     '3360',
        }
    }
    
    DATABASE_ROUTERS = ['genes.routers.GeneRouter',]
    

    routers.py

    class GeneRouter(object):
        """A router to control all database operations on models in
        the genes application"""
    
        def db_for_read(self, model, **hints):
            "Point all operations on genes models to 'genes'"
            if model._meta.app_label == 'genes':
                return 'remrate'
            return None
    
        def db_for_write(self, model, **hints):
            "Point all operations on genes models to 'genes'"
            if model._meta.app_label == 'genes':
                return 'remrate'
            return None
    
        def allow_syncdb(self, db, model):
            "Make sure the genes app only appears on the 'genes' db"
            if model._meta.app_label in ['south']:
                return True
            if db == 'remrate':
                return model._meta.app_label == 'genes'
            elif model._meta.app_label == 'genes':
                return False
            return None
    

    One you have this set up then you need to create the models.py file for the

    models.py

    class Hello(models.Model):
        """Hello model"""
    
        field1 = models.CharField(max_length=64)
    
        class Meta:
            db_table = u'hello'
            managed = False
    

    To do this progmatically..

    python manage.py inspectdb
    

    Once this is done – you should be able to Query using standard Django querysets

    Hello.objects.all()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make some data from database available using XML, I have
I have configured in following way that spring MVC app using Spring 3.1.1.RELEASE web.xml
I have configured Apache httpd to work as a forward proxy server. How can
I have a database table containing departments. I have another table containing people. As
OSX machine running MAMP. CakePHP 2.2.1 installed and configured properly (meaning that I have
We use EclipseLink for persistence, and have configured EclipseLink to automatically create the database
I have a tomcat instance setup but the database connection I have configured in
I have configured the maven-sql plugin to execute the insert and delete scripts for
I have configured Mod Security on Apache 2.2.21 and i have successfully configured Mod
I have configured Plone with the following buildout (via http://build.pythonpackages.com/buildout/plone/4.2.x ): [buildout] allow-hosts =

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.