Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REUSE_DB=1 support for multiple databases #129

Open
gabewb opened this issue Jun 21, 2013 · 1 comment
Open

REUSE_DB=1 support for multiple databases #129

gabewb opened this issue Jun 21, 2013 · 1 comment

Comments

@gabewb
Copy link

gabewb commented Jun 21, 2013

(cross-posted here: http://stackoverflow.com/questions/17279806/is-there-a-way-to-tell-django-nose-to-handle-multiple-databases)

In settings.py I have:

DATABASES = {
    'default': {
        'ENGINE': 'mysql_pymysql',
        'NAME': 'OST_DEV_1',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306',
    },
    'umc': {
        'ENGINE': 'mysql_pymysql',
        'NAME': 'UMC',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

This works fine (but slowly, of course):

./manage.py test myapp

But this fails:

REUSE_DB=1 ./manage.py test myapp
DatabaseError: (1146, u"Table 'OST_DEV_1.tblMfg' doesn't exist")

But tblMfg is in UMC, not OST_DEV_1.

We currently use 'using' manually for the objects that are in UMC:

        active_mfgs = Mfg.objects.using('umc').filter(status="ACTIVE")

Is there a way to tell django-nose to treat these two databases separately?

@enoren
Copy link

enoren commented Jan 6, 2014

I am seeing this issue as well with Django 1.5 when I was not seeing the issue with Django 1.4. It appears that from 1.4 to 1.5 Django would establish a connection to the databases ahead of calling the setup_databases method of the NoseTestSuiteRunner which would have the effect that the test for _should_create_database would come back with information about the main database and not the test database since the preexisting connection was created against the main DB.

The fix for this is easy and is really just adding a call to connection.close() right before doing the _should_create_database call in NoseTestSuiteRunner.setup_databases()

I will submit a patch for this.

enoren pushed a commit to enoren/django-nose that referenced this issue Jan 6, 2014
…reliably when dealing with multiple DB's.
@jwhitlock jwhitlock added the bug label Jul 3, 2015
@jwhitlock jwhitlock added this to the Database Testing milestone Jul 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants