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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:31:03+00:00 2026-05-26T18:31:03+00:00

I have a project (#1) with a couple apps in it using a mysql

  • 0

I have a project (#1) with a couple apps in it using a mysql database #1. I also have another project (#2) whose django code is on the same server, but it uses a different mysql database (#2).

My goal is to be running a web app in project #1 and use the django models from project #2 for a simple query against db #2. However, when I import from project #2, it still uses the #1 database, even though the settings.py file for #2 is appropriately using database #2 (i.e. when I run the web app in project #2, it works fine).

Here is the entirety of a file that I can successfully run as a standalone script. Sadly, when I import the file into project #1 and run the function, it fails (because it is looking in db#1 for the table):

import sys

def get_stuff_from_project2(ids):
    from django.core.management import setup_environ
    from project2 import settings
    setup_environ(settings)

    from project2.myapp2.models import mymodel2

    all_rows = mymodel2.objects.filter(id__in=ids).values()
    return(all_rows)

# as a standalone script, run the main function
if __name__ == "__main__":
    sys.path.append("/home/me/django")
    print str ( get_stuff_from_project2( sys.argv[1:] ) )

Again, this works as a standalone script. But, from project #1 (using code below) it fails with a DatabaseError, Table ‘db1.myapp2_mymodel2’ doesn’t exist:

from project1.myapp1.standalone_script import get_stuff_from_project2
all_rows = get_stuff_from_project2( ids )

My guess here is that the setup_environ function does not actually process the new DATABASE_NAME, or that it can’t change an existing DATABASE_NAME once the settings have been set?

I’m a bit lost at this point and have been trying to search for a solution. I don’t really want to go down the “multi-site” or “multi-database” approach, since I would really like to keep project 1 and project 2 as separate as possible. My alternative would be to call the standalone script as a system call from within project 1, or to make a view in project 2 which is an API and sends data out. But, I thought that just using a model would be simplest if it worked.

Thanks.

——- added April 13, 11:35 PST —-

Here’s a simpler version of the question: How can I access two different projects from a single standalone script. The following code works ok for whichever project I do setup_environ on first, but it can’t do the second one:

import sys
from django.core.management import setup_environ
sys.path.append('/home/me/django')

from project1 import settings
print setup_environ(settings)  # shows /home/me/django/project1
print settings.DATABASE_NAME   # shows db1
from project1.myapp1.models import mymodel1
mymodel1.objects.filter(id=9376544).values()  # works fine

from project2 import settings
print setup_environ(settings)  # shows /home/me/django/project2
print settings.DATABASE_NAME   # shows db2
from project2.myapp2.models import mymodel2
mymodel2.objects.filter(id=6544).values() # fails with:
# django.db.utils.DatabaseError: (1146, "Table 'db1.myapp2_mymodel2' doesn't exist")
  • 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-26T18:31:04+00:00Added an answer on May 26, 2026 at 6:31 pm

    I was unable to solve this using a single script. I instead used two scripts: the first called the second as a shell command, and the second output formatted data as a list to stdout.

    This has been robust enough for the problem of reading a single stream of data from another app’s database, but would not be suitable for a larger problem such as requiring several queries or writing to the second app’s data. For the more complex problem, add APIs (XMLRPC, REST are easy in Django) to make calls into the running apps.

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

Sidebar

Related Questions

I'm considering using Grails for my current project. I have a couple of requirements
I'm using Django for a project, and I want to use a couple of
So in my Django project I have a few different apps, each with their
I'm working on a project with couple others. We all have local copies of
I have a VS2005 project that contains a couple web service references. The project
I have a small software project with a couple clients. What I'm looking for
I have created a couple of java working sets for a project in my
I'm looking to have a couple of plugins in a Flex project I'm working
We have a project using LINQ to SQL, for which I need to rewrite
Due to a merger, we have inherited a couple of legacy apps which run

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.