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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:10:11+00:00 2026-06-11T16:10:11+00:00

I have been trying since this morning and have read all the posts here

  • 0

I have been trying since this morning and have read all the posts here and all over about accessing multiple databases in django with no avail. I m looking to access another database on the same server and I have included the databases in the settings.py with aliases. When I m trying to use the using() in the queryset I m getting an error that the Global name ‘Objectname’ does not exists. I m using postgresql 9.1 with django 1.4

Is there anything that I need to import for this to work? Its not working for me either in the console (python manage.py shell) or the views.

Here is the database setup from settings.py:

DATABASES = {
 'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',     # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'testing',      # Or path to database file if using sqlite3.
    'USER': 'xxxx',                     # Not used with sqlite3.
    'PASSWORD': 'xxxx',                 # Not used with sqlite3.
    'HOST': 'localhost',                    # Set to empty string for localhost. Not used with sqlite3.
    'PORT': 'xxxx',                         # Set to empty string for default. Not used with sqlite3.
},
'app_data': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',     # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'applications',      # Or path to database file if using sqlite3.
    'USER': 'xxxx',                     # Not used with sqlite3.
    'PASSWORD': 'xxxx',                 # Not used with sqlite3.
    'HOST': 'localhost',                    # Set to empty string for localhost. Not used with sqlite3.
    'PORT': 'xxxx',                         # Set to empty string for default. Not used with sqlite3.
},
'ppp_data': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',     # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'platform',      # Or path to database file if using sqlite3.
    'USER': 'xxxx',                     # Not used with sqlite3.
    'PASSWORD': 'xxxx',                 # Not used with sqlite3.
    'HOST': 'localhost',                    # Set to empty string for localhost. Not used with sqlite3.
    'PORT': 'xxxx',                         # Set to empty string for default. Not used with sqlite3.
}

}

Here is the code from the console:

>>> MyModel.objects.using('app_data').all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'MyModel' is not defined

Here is the error from the view:

NameError at /myapp/view
global name 'MyModel' is not defined

Please help!

Edited: Just to give a little background I have 3 different apps running on one server with different databases and I wanted to access records across different apps just for viewing.
The 3 apps are app, ppp and testing and I m trying to access app and ppp data from my testing app.

  • 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-11T16:10:12+00:00Added an answer on June 11, 2026 at 4:10 pm

    I had to append the app paths for other apps to the wsgi file.

    import os, sys
    sys.path.append('/opt/www/test')
    sys.path.append('/opt/www/app')
    sys.path.append('/opt/www/ppp')
    

    Then I could import the models from other apps

    from pp_app.myapp.models import MyModel
    from pp_ppp.myapp.models import MyModel
    

    Then this allowed me to use the using() method in the views to get the records:

    data1 = MyModel.objects.using('app_data').all() 
    data2 = MyModel.objects.using('ppp_data').all() 
    

    Hope this helps someone else.

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

Sidebar

Related Questions

I've been trying to resolve this issue since morning. I have client and server
I've been trying to solve this problem since this morning, and I know I'm
I have been trying to follow the example in this post . Since I
I am new to C# .NET. I have been trying since 2 days, but
I've been trying to use 'import poplib' to access gmail, since I have Pop
I have been trying since yesterday to get google like paging, but each time
I have been trying this for a while but can't find the right solution.
I have been trying to execute this program on my MinGW, through Code::Blocks: #include
I have been trying for days to figure out how to parse this JSON
Ever since reading Clean Code I have been trying to keep my code descriptive

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.