Django测试运行程序找不到非默认数据库连接

Django测试运行程序找不到非默认数据库连接,django,python-2.7,unit-testing,Django,Python 2.7,Unit Testing,我的Django应用程序运行良好,但Django的内置单元测试有问题。使用默认数据库以外的数据库在应用程序上运行Django测试运行程序时,我收到一个错误: python manage.py test qc ... File "/usr/lib64/python2.7/site-packages/django/db/utils.py", line 179, in ensure_defaults raise ConnectionDoesNotExist("The con

我的Django应用程序运行良好,但Django的内置单元测试有问题。使用默认数据库以外的数据库在应用程序上运行Django测试运行程序时,我收到一个错误:

python manage.py test qc
...      
File "/usr/lib64/python2.7/site-packages/django/db/utils.py", line 179, in ensure_defaults
        raise ConnectionDoesNotExist("The connection %s doesn't exist" % alias)
    ConnectionDoesNotExist: The connection other_db doesn't exist
在settings.py中:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db_default',
        'USER': 'xxx',
        'PASSWORD': 'yyy',
        'HOST': os.environ["MYSQL_HOST"],
        'PORT': os.environ["MYSQL_PORT"],
    },
    'other_db': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db_other',
        'USER': 'xxx',
        'PASSWORD': 'yyy',
        'HOST': os.environ["MYSQL_HOST"],
        'PORT': os.environ["MYSQL_PORT"],
    }
}
可能相关,在routers.py中:

def allow_migrate(self, db, app_label, model_name=None, **hints):

    if hints.has_key('model'):
        model = hints['model']

        if db == 'other_db':
            return model._meta.app_label == 'qc'
        elif model._meta.app_label == 'qc':
            return False
        return None
    else:
        if db == 'other_db':
            return app_label == 'qc'
        elif app_label == 'qc':
            return False
我试图在qc/tests.py中运行的测试用例:

from django.test import TestCase
from qc.models import *

class HybridTestCase(TestCase):

    def setUp(self):
        baseA = MyModel.objects.create(id='A',name="NonName")

Django版本:1.9.8。我在一个码头工人里面用CentOS 7运行

问题是我在settings.py文件中覆盖了数据库字典,以防测试:

if 'test' in sys.argv:
    DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3'}}
在为“other_db”添加内存数据库后,事情又开始了:

if 'test' in sys.argv:
    DATABASES = {
                 'default': {'ENGINE': 'django.db.backends.sqlite3'}, 
                 'other_db': {'ENGINE': 'django.db.backends.sqlite3'}
                }