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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:19:04+00:00 2026-05-24T11:19:04+00:00

I have a django project using multiple databases. I am using django-nose as the

  • 0

I have a django project using multiple databases. I am using django-nose as the test runner. Test data is loaded to the default database using fixtures. I have a second database not managed by django models, where I want to create a structure and load some data before testing, using raw sql.

Is there any way to do this in a somehow clean way?

Thank you.

  • 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-24T11:19:04+00:00Added an answer on May 24, 2026 at 11:19 am

    Ht Stathis,

    Here was my scenario and how I solved it – YMMV..

    1) I build up a testrunner and overriding the setup_databases method. I needed to do this because I wanted to externally create this database. We had custom tables, and functions. I literally used the same code with one small deviation

    class IManageTestRunner(DjangoTestSuiteRunner):
        """This is a 3 line addition to the original method"""
    
        def setup_databases(self, **kwargs):
            from django.db import connections, DEFAULT_DB_ALIAS
    
            ### Skipped for brevity ###
    
            for signature, (db_name, aliases) in dependency_ordered(test_databases.items(), dependencies):
                # Actually create the database for the first connection
                connection = connections[aliases[0]]
                old_names.append((connection, db_name, True))
                test_db_name = connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
    
                # Our little hack...
                if db_name == "bugs":
                    create_IManage_instance(django_created_sql = True, mysql_db = "test_bugs",
                                        arg = value, arg2 = value )
                # End of our little hack..
    
                for alias in aliases[1:]:
                    connection = connections[alias]
    
                    ### Skipped for brevity ###
    

    2) Add this to your settings.py
    TEST_RUNNER = 'IManageTestRunner'

    3) Once this was created then I knew my test db was created. I would then create tests which populated externally and test the results against it.

    def test_add_property_value(self):
        """Test set / get a value"""
        # This will do some external process which occcurs to the db.
        pm = Pm(mysql_db='test_bugs', p4_port = settings.ICMSERVER_TEST_PORT)
        pmsite, pmproject, pmvariant, pmlibtype, pmlibrary, pmrelease = pm.add_release_tree()
        prop_type, pmvalue = ("string", "Funny Business")
        pmproperty = "%s_%s_basic" % (pmproject.name, prop_type)
        pm.add_property_definition(pmproperty, prop_type=prop_type)
        pm.add_propval(pmproperty, value=pmvalue, project=pmproject.name)
    
        # Now use Django to pull the value back out..
        project = Project.objects.get(name=pmproject.name)
        property = project.get_property(pmproperty)
        self.assertEqual(pmvalue, property.value)
    

    Hope that helps took me awhile to figure it out. I still have one issue (doing repeat inserts/queries..)

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

Sidebar

Related Questions

Is it possible and correct to have multiple sites under single django project. So
I have a Django project where I have been logging to a file using
I have a client's Django project that I'm developing locally, using Mercurial for version
Im using python markdown for my django project, when i have the value #/usr/bin/env
I have a medium sized Django project, (running on AppEngine if it makes any
I have worked a bit with Django and I quite like its project/applications model
I have a Django project, that has a Address model. This is used in
I have a project w/ multiple apps. I am attempting to use the dumpdata
I want to create a rollback button in my django project using MySQLdb. I
We have a Django project which runs on Google App Engine and used db.UserProperty

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.